Java 类org.bouncycastle.asn1.DERUniversalString 实例源码

项目:ipack    文件:DirectoryString.java   
public static DirectoryString getInstance(Object o)
{
    if (o == null || o instanceof DirectoryString)
    {
        return (DirectoryString)o;
    }

    if (o instanceof DERT61String)
    {
        return new DirectoryString((DERT61String)o);
    }

    if (o instanceof DERPrintableString)
    {
        return new DirectoryString((DERPrintableString)o);
    }

    if (o instanceof DERUniversalString)
    {
        return new DirectoryString((DERUniversalString)o);
    }

    if (o instanceof DERUTF8String)
    {
        return new DirectoryString((DERUTF8String)o);
    }

    if (o instanceof DERBMPString)
    {
        return new DirectoryString((DERBMPString)o);
    }

    throw new IllegalArgumentException("illegal object in getInstance: " + o.getClass().getName());
}
项目:xitk    文件:X509Util.java   
public static String rdnValueToString(ASN1Encodable value) {
    ParamUtil.requireNonNull("value", value);
    if (value instanceof ASN1String && !(value instanceof DERUniversalString)) {
        return ((ASN1String) value).getString();
    } else {
        try {
            return "#" + bytesToString(
                    Hex.encode(value.toASN1Primitive().getEncoded(ASN1Encoding.DER)));
        } catch (IOException ex) {
            throw new IllegalArgumentException("other value has no encoded form");
        }
    }
}
项目:gwt-crypto    文件:DirectoryString.java   
public static DirectoryString getInstance(Object o)
{
    if (o == null || o instanceof DirectoryString)
    {
        return (DirectoryString)o;
    }

    if (o instanceof DERT61String)
    {
        return new DirectoryString((DERT61String)o);
    }

    if (o instanceof DERPrintableString)
    {
        return new DirectoryString((DERPrintableString)o);
    }

    if (o instanceof DERUniversalString)
    {
        return new DirectoryString((DERUniversalString)o);
    }

    if (o instanceof DERUTF8String)
    {
        return new DirectoryString((DERUTF8String)o);
    }

    if (o instanceof DERBMPString)
    {
        return new DirectoryString((DERBMPString)o);
    }

    throw new IllegalArgumentException("illegal object in getInstance: " + o.getClass().getName());
}
项目:Aki-SSL    文件:DirectoryString.java   
public static DirectoryString getInstance(Object o)
{
    if (o == null || o instanceof DirectoryString)
    {
        return (DirectoryString)o;
    }

    if (o instanceof DERT61String)
    {
        return new DirectoryString((DERT61String)o);
    }

    if (o instanceof DERPrintableString)
    {
        return new DirectoryString((DERPrintableString)o);
    }

    if (o instanceof DERUniversalString)
    {
        return new DirectoryString((DERUniversalString)o);
    }

    if (o instanceof DERUTF8String)
    {
        return new DirectoryString((DERUTF8String)o);
    }

    if (o instanceof DERBMPString)
    {
        return new DirectoryString((DERBMPString)o);
    }

    throw new IllegalArgumentException("illegal object in getInstance: " + o.getClass().getName());
}
项目:keystore-explorer    文件:Asn1Dump.java   
private String dumpString(ASN1String asn1String) {
    StringBuilder sb = new StringBuilder();

    sb.append(indentSequence.toString(indentLevel));

    if (asn1String instanceof DERBMPString) {
        sb.append("BMP STRING=");
    } else if (asn1String instanceof DERGeneralString) {
        sb.append("GENERAL STRING=");
    } else if (asn1String instanceof DERIA5String) {
        sb.append("IA5 STRING=");
    } else if (asn1String instanceof DERNumericString) {
        sb.append("NUMERIC STRING=");
    } else if (asn1String instanceof DERPrintableString) {
        sb.append("PRINTABLE STRING=");
    } else if (asn1String instanceof DERT61String) {
        sb.append("TELETEX STRING=");
    } else if (asn1String instanceof DERUniversalString) {
        sb.append("UNIVERSAL STRING=");
    } else if (asn1String instanceof DERUTF8String) {
        sb.append("UTF8 STRING=");
    } else if (asn1String instanceof DERVisibleString) {
        sb.append("VISIBLE STRING=");
    } else {
        sb.append("UNKNOWN STRING=");
    }

    sb.append("'");
    sb.append(asn1String.getString());
    sb.append("'");
    sb.append(NEWLINE);

    return sb.toString();
}
项目:TinyTravelTracker    文件:DirectoryString.java   
public static DirectoryString getInstance(Object o)
{
    if (o == null || o instanceof DirectoryString)
    {
        return (DirectoryString)o;
    }

    if (o instanceof DERT61String)
    {
        return new DirectoryString((DERT61String)o);
    }

    if (o instanceof DERPrintableString)
    {
        return new DirectoryString((DERPrintableString)o);
    }

    if (o instanceof DERUniversalString)
    {
        return new DirectoryString((DERUniversalString)o);
    }

    if (o instanceof DERUTF8String)
    {
        return new DirectoryString((DERUTF8String)o);
    }

    if (o instanceof DERBMPString)
    {
        return new DirectoryString((DERBMPString)o);
    }

    throw new IllegalArgumentException("illegal object in getInstance: " + o.getClass().getName());
}
项目:CryptMeme    文件:DirectoryString.java   
public static DirectoryString getInstance(Object o)
{
    if (o == null || o instanceof DirectoryString)
    {
        return (DirectoryString)o;
    }

    if (o instanceof DERT61String)
    {
        return new DirectoryString((DERT61String)o);
    }

    if (o instanceof DERPrintableString)
    {
        return new DirectoryString((DERPrintableString)o);
    }

    if (o instanceof DERUniversalString)
    {
        return new DirectoryString((DERUniversalString)o);
    }

    if (o instanceof DERUTF8String)
    {
        return new DirectoryString((DERUTF8String)o);
    }

    if (o instanceof DERBMPString)
    {
        return new DirectoryString((DERBMPString)o);
    }

    throw new IllegalArgumentException("illegal object in getInstance: " + o.getClass().getName());
}
项目:xipki    文件:BaseX509Certprofile.java   
private static RDN createPostalAddressRdn(ASN1ObjectIdentifier type, ASN1Encodable rdnValue,
        RdnControl control, int index) throws BadCertTemplateException {
    ParamUtil.requireNonNull("type", type);

    if (!(rdnValue instanceof ASN1Sequence)) {
        throw new BadCertTemplateException(
                "rdnValue of RDN postalAddress has incorrect syntax");
    }

    ASN1Sequence seq = (ASN1Sequence) rdnValue;
    final int size = seq.size();
    if (size < 1 || size > 6) {
        throw new BadCertTemplateException(
                "Sequence size of RDN postalAddress is not within [1, 6]: " + size);
    }

    ASN1EncodableVector vec = new ASN1EncodableVector();
    for (int i = 0; i < size; i++) {
        ASN1Encodable line = seq.getObjectAt(i);
        String text;
        if (line instanceof ASN1String && !(line instanceof DERUniversalString)) {
            text = ((ASN1String) line).getString();
        } else {
            throw new BadCertTemplateException(
                String.format("postalAddress[%d] has incorrect syntax", i));
        }

        ASN1Encodable asn1Line = createRdnValue(text, type, control, index);
        vec.add(asn1Line);
    }

    return new RDN(type, new DERSequence(vec));
}
项目:irma_future_id    文件:DirectoryString.java   
public static DirectoryString getInstance(Object o)
{
    if (o == null || o instanceof DirectoryString)
    {
        return (DirectoryString)o;
    }

    if (o instanceof DERT61String)
    {
        return new DirectoryString((DERT61String)o);
    }

    if (o instanceof DERPrintableString)
    {
        return new DirectoryString((DERPrintableString)o);
    }

    if (o instanceof DERUniversalString)
    {
        return new DirectoryString((DERUniversalString)o);
    }

    if (o instanceof DERUTF8String)
    {
        return new DirectoryString((DERUTF8String)o);
    }

    if (o instanceof DERBMPString)
    {
        return new DirectoryString((DERBMPString)o);
    }

    throw new IllegalArgumentException("illegal object in getInstance: " + o.getClass().getName());
}
项目:bc-java    文件:DirectoryString.java   
public static DirectoryString getInstance(Object o)
{
    if (o == null || o instanceof DirectoryString)
    {
        return (DirectoryString)o;
    }

    if (o instanceof DERT61String)
    {
        return new DirectoryString((DERT61String)o);
    }

    if (o instanceof DERPrintableString)
    {
        return new DirectoryString((DERPrintableString)o);
    }

    if (o instanceof DERUniversalString)
    {
        return new DirectoryString((DERUniversalString)o);
    }

    if (o instanceof DERUTF8String)
    {
        return new DirectoryString((DERUTF8String)o);
    }

    if (o instanceof DERBMPString)
    {
        return new DirectoryString((DERBMPString)o);
    }

    throw new IllegalArgumentException("illegal object in getInstance: " + o.getClass().getName());
}
项目:ipack    文件:X509Name.java   
/**
 * Constructor from ASN1Sequence
 *
 * the principal will be a list of constructed sets, each containing an (OID, String) pair.
 * @deprecated use X500Name.getInstance()
 */
public X509Name(
    ASN1Sequence  seq)
{
    this.seq = seq;

    Enumeration e = seq.getObjects();

    while (e.hasMoreElements())
    {
        ASN1Set         set = ASN1Set.getInstance(((ASN1Encodable)e.nextElement()).toASN1Primitive());

        for (int i = 0; i < set.size(); i++) 
        {
               ASN1Sequence s = ASN1Sequence.getInstance(set.getObjectAt(i).toASN1Primitive());

               if (s.size() != 2)
               {
                   throw new IllegalArgumentException("badly sized pair");
               }

               ordering.addElement(ASN1ObjectIdentifier.getInstance(s.getObjectAt(0)));

               ASN1Encodable value = s.getObjectAt(1);
               if (value instanceof ASN1String && !(value instanceof DERUniversalString))
               {
                   String v = ((ASN1String)value).getString();
                   if (v.length() > 0 && v.charAt(0) == '#')
                   {
                       values.addElement("\\" + v);
                   }
                   else
                   {
                       values.addElement(v);
                   }
               }
               else
               {
                   try
                   {
                       values.addElement("#" + bytesToString(Hex.encode(value.toASN1Primitive().getEncoded(ASN1Encoding.DER))));
                   }
                   catch (IOException e1)
                   {
                       throw new IllegalArgumentException("cannot encode value");
                   }
               }
               added.addElement((i != 0) ? TRUE : FALSE);  // to allow earlier JDK compatibility
        }
    }
}
项目:ipack    文件:DirectoryString.java   
private DirectoryString(
    DERUniversalString string)
{
    this.string = string;
}
项目:ipack    文件:IETFUtils.java   
public static String valueToString(ASN1Encodable value)
{
    StringBuffer vBuf = new StringBuffer();

    if (value instanceof ASN1String && !(value instanceof DERUniversalString))
    {
        String v = ((ASN1String)value).getString();
        if (v.length() > 0 && v.charAt(0) == '#')
        {
            vBuf.append("\\" + v);
        }
        else
        {
            vBuf.append(v);
        }
    }
    else
    {
        try
        {
            vBuf.append("#" + bytesToString(Hex.encode(value.toASN1Primitive().getEncoded(ASN1Encoding.DER))));
        }
        catch (IOException e)
        {
            throw new IllegalArgumentException("Other value has no encoded form");
        }
    }

    int     end = vBuf.length();
    int     index = 0;

    if (vBuf.length() >= 2 && vBuf.charAt(0) == '\\' && vBuf.charAt(1) == '#')
    {
        index += 2;
    }

    while (index != end)
    {
        if ((vBuf.charAt(index) == ',')
           || (vBuf.charAt(index) == '"')
           || (vBuf.charAt(index) == '\\')
           || (vBuf.charAt(index) == '+')
           || (vBuf.charAt(index) == '=')
           || (vBuf.charAt(index) == '<')
           || (vBuf.charAt(index) == '>')
           || (vBuf.charAt(index) == ';'))
        {
            vBuf.insert(index, "\\");
            index++;
            end++;
        }

        index++;
    }

    int start = 0;
    if (vBuf.length() > 0)
    {
        while (vBuf.charAt(start) == ' ')
        {
            vBuf.insert(start, "\\");
            start += 2;
        }
    }

    int endBuf = vBuf.length() - 1;

    while (endBuf >= 0 && vBuf.charAt(endBuf) == ' ')
    {
        vBuf.insert(endBuf, '\\');
        endBuf--;
    }

    return vBuf.toString();
}
项目:gwt-crypto    文件:X509Name.java   
/**
 * Constructor from ASN1Sequence
 *
 * the principal will be a list of constructed sets, each containing an (OID, String) pair.
 * @deprecated use X500Name.getInstance()
 */
public X509Name(
    ASN1Sequence  seq)
{
    this.seq = seq;

    Enumeration e = seq.getObjects();

    while (e.hasMoreElements())
    {
        ASN1Set         set = ASN1Set.getInstance(((ASN1Encodable)e.nextElement()).toASN1Primitive());

        for (int i = 0; i < set.size(); i++) 
        {
               ASN1Sequence s = ASN1Sequence.getInstance(set.getObjectAt(i).toASN1Primitive());

               if (s.size() != 2)
               {
                   throw new IllegalArgumentException("badly sized pair");
               }

               ordering.addElement(ASN1ObjectIdentifier.getInstance(s.getObjectAt(0)));

               ASN1Encodable value = s.getObjectAt(1);
               if (value instanceof ASN1String && !(value instanceof DERUniversalString))
               {
                   String v = ((ASN1String)value).getString();
                   if (v.length() > 0 && v.charAt(0) == '#')
                   {
                       values.addElement("\\" + v);
                   }
                   else
                   {
                       values.addElement(v);
                   }
               }
               else
               {
                   try
                   {
                       values.addElement("#" + bytesToString(Hex.encode(value.toASN1Primitive().getEncoded(ASN1Encoding.DER))));
                   }
                   catch (IOException e1)
                   {
                       throw new IllegalArgumentException("cannot encode value");
                   }
               }
               added.addElement((i != 0) ? TRUE : FALSE);  // to allow earlier JDK compatibility
        }
    }
}
项目:gwt-crypto    文件:DirectoryString.java   
private DirectoryString(
    DERUniversalString string)
{
    this.string = string;
}
项目:gwt-crypto    文件:IETFUtils.java   
public static String valueToString(ASN1Encodable value)
{
    StringBuffer vBuf = new StringBuffer();

    if (value instanceof ASN1String && !(value instanceof DERUniversalString))
    {
        String v = ((ASN1String)value).getString();
        if (v.length() > 0 && v.charAt(0) == '#')
        {
            vBuf.append("\\" + v);
        }
        else
        {
            vBuf.append(v);
        }
    }
    else
    {
        try
        {
            vBuf.append("#" + bytesToString(Hex.encode(value.toASN1Primitive().getEncoded(ASN1Encoding.DER))));
        }
        catch (IOException e)
        {
            throw new IllegalArgumentException("Other value has no encoded form");
        }
    }

    int     end = vBuf.length();
    int     index = 0;

    if (vBuf.length() >= 2 && vBuf.charAt(0) == '\\' && vBuf.charAt(1) == '#')
    {
        index += 2;
    }

    while (index != end)
    {
        if ((vBuf.charAt(index) == ',')
           || (vBuf.charAt(index) == '"')
           || (vBuf.charAt(index) == '\\')
           || (vBuf.charAt(index) == '+')
           || (vBuf.charAt(index) == '=')
           || (vBuf.charAt(index) == '<')
           || (vBuf.charAt(index) == '>')
           || (vBuf.charAt(index) == ';'))
        {
            vBuf.insert(index, "\\");
            index++;
            end++;
        }

        index++;
    }

    int start = 0;
    if (vBuf.length() > 0)
    {
        while (vBuf.length() > start && vBuf.charAt(start) == ' ')
        {
            vBuf.insert(start, "\\");
            start += 2;
        }
    }

    int endBuf = vBuf.length() - 1;

    while (endBuf >= 0 && vBuf.charAt(endBuf) == ' ')
    {
        vBuf.insert(endBuf, '\\');
        endBuf--;
    }

    return vBuf.toString();
}
项目:Aki-SSL    文件:X509Name.java   
/**
 * Constructor from ASN1Sequence
 *
 * the principal will be a list of constructed sets, each containing an (OID, String) pair.
 * @deprecated use X500Name.getInstance()
 */
public X509Name(
    ASN1Sequence  seq)
{
    this.seq = seq;

    Enumeration e = seq.getObjects();

    while (e.hasMoreElements())
    {
        ASN1Set         set = ASN1Set.getInstance(((ASN1Encodable)e.nextElement()).toASN1Primitive());

        for (int i = 0; i < set.size(); i++) 
        {
               ASN1Sequence s = ASN1Sequence.getInstance(set.getObjectAt(i).toASN1Primitive());

               if (s.size() != 2)
               {
                   throw new IllegalArgumentException("badly sized pair");
               }

               ordering.addElement(ASN1ObjectIdentifier.getInstance(s.getObjectAt(0)));

               ASN1Encodable value = s.getObjectAt(1);
               if (value instanceof ASN1String && !(value instanceof DERUniversalString))
               {
                   String v = ((ASN1String)value).getString();
                   if (v.length() > 0 && v.charAt(0) == '#')
                   {
                       values.addElement("\\" + v);
                   }
                   else
                   {
                       values.addElement(v);
                   }
               }
               else
               {
                   try
                   {
                       values.addElement("#" + bytesToString(Hex.encode(value.toASN1Primitive().getEncoded(ASN1Encoding.DER))));
                   }
                   catch (IOException e1)
                   {
                       throw new IllegalArgumentException("cannot encode value");
                   }
               }
               added.addElement((i != 0) ? TRUE : FALSE);  // to allow earlier JDK compatibility
        }
    }
}
项目:Aki-SSL    文件:DirectoryString.java   
private DirectoryString(
    DERUniversalString string)
{
    this.string = string;
}
项目:Aki-SSL    文件:IETFUtils.java   
public static String valueToString(ASN1Encodable value)
{
    StringBuffer vBuf = new StringBuffer();

    if (value instanceof ASN1String && !(value instanceof DERUniversalString))
    {
        String v = ((ASN1String)value).getString();
        if (v.length() > 0 && v.charAt(0) == '#')
        {
            vBuf.append("\\" + v);
        }
        else
        {
            vBuf.append(v);
        }
    }
    else
    {
        try
        {
            vBuf.append("#" + bytesToString(Hex.encode(value.toASN1Primitive().getEncoded(ASN1Encoding.DER))));
        }
        catch (IOException e)
        {
            throw new IllegalArgumentException("Other value has no encoded form");
        }
    }

    int     end = vBuf.length();
    int     index = 0;

    if (vBuf.length() >= 2 && vBuf.charAt(0) == '\\' && vBuf.charAt(1) == '#')
    {
        index += 2;
    }

    while (index != end)
    {
        if ((vBuf.charAt(index) == ',')
           || (vBuf.charAt(index) == '"')
           || (vBuf.charAt(index) == '\\')
           || (vBuf.charAt(index) == '+')
           || (vBuf.charAt(index) == '=')
           || (vBuf.charAt(index) == '<')
           || (vBuf.charAt(index) == '>')
           || (vBuf.charAt(index) == ';'))
        {
            vBuf.insert(index, "\\");
            index++;
            end++;
        }

        index++;
    }

    int start = 0;
    if (vBuf.length() > 0)
    {
        while (vBuf.length() > start && vBuf.charAt(start) == ' ')
        {
            vBuf.insert(start, "\\");
            start += 2;
        }
    }

    int endBuf = vBuf.length() - 1;

    while (endBuf >= 0 && vBuf.charAt(endBuf) == ' ')
    {
        vBuf.insert(endBuf, '\\');
        endBuf--;
    }

    return vBuf.toString();
}
项目:TinyTravelTracker    文件:X509Name.java   
/**
 * Constructor from ASN1Sequence
 *
 * the principal will be a list of constructed sets, each containing an (OID, String) pair.
 * @deprecated use X500Name.getInstance()
 */
public X509Name(
    ASN1Sequence  seq)
{
    this.seq = seq;

    Enumeration e = seq.getObjects();

    while (e.hasMoreElements())
    {
        ASN1Set         set = ASN1Set.getInstance(((ASN1Encodable)e.nextElement()).toASN1Primitive());

        for (int i = 0; i < set.size(); i++) 
        {
               ASN1Sequence s = ASN1Sequence.getInstance(set.getObjectAt(i).toASN1Primitive());

               if (s.size() != 2)
               {
                   throw new IllegalArgumentException("badly sized pair");
               }

               ordering.addElement(ASN1ObjectIdentifier.getInstance(s.getObjectAt(0)));

               ASN1Encodable value = s.getObjectAt(1);
               if (value instanceof ASN1String && !(value instanceof DERUniversalString))
               {
                   String v = ((ASN1String)value).getString();
                   if (v.length() > 0 && v.charAt(0) == '#')
                   {
                       values.addElement("\\" + v);
                   }
                   else
                   {
                       values.addElement(v);
                   }
               }
               else
               {
                   try
                   {
                       values.addElement("#" + bytesToString(Hex.encode(value.toASN1Primitive().getEncoded(ASN1Encoding.DER))));
                   }
                   catch (IOException e1)
                   {
                       throw new IllegalArgumentException("cannot encode value");
                   }
               }
               added.addElement((i != 0) ? TRUE : FALSE);  // to allow earlier JDK compatibility
        }
    }
}
项目:TinyTravelTracker    文件:DirectoryString.java   
private DirectoryString(
    DERUniversalString string)
{
    this.string = string;
}
项目:TinyTravelTracker    文件:IETFUtils.java   
public static String valueToString(ASN1Encodable value)
{
    StringBuffer vBuf = new StringBuffer();

    if (value instanceof ASN1String && !(value instanceof DERUniversalString))
    {
        String v = ((ASN1String)value).getString();
        if (v.length() > 0 && v.charAt(0) == '#')
        {
            vBuf.append("\\" + v);
        }
        else
        {
            vBuf.append(v);
        }
    }
    else
    {
        try
        {
            vBuf.append("#" + bytesToString(Hex.encode(value.toASN1Primitive().getEncoded(ASN1Encoding.DER))));
        }
        catch (IOException e)
        {
            throw new IllegalArgumentException("Other value has no encoded form");
        }
    }

    int     end = vBuf.length();
    int     index = 0;

    if (vBuf.length() >= 2 && vBuf.charAt(0) == '\\' && vBuf.charAt(1) == '#')
    {
        index += 2;
    }

    while (index != end)
    {
        if ((vBuf.charAt(index) == ',')
           || (vBuf.charAt(index) == '"')
           || (vBuf.charAt(index) == '\\')
           || (vBuf.charAt(index) == '+')
           || (vBuf.charAt(index) == '=')
           || (vBuf.charAt(index) == '<')
           || (vBuf.charAt(index) == '>')
           || (vBuf.charAt(index) == ';'))
        {
            vBuf.insert(index, "\\");
            index++;
            end++;
        }

        index++;
    }

    int start = 0;
    if (vBuf.length() > 0)
    {
        while (vBuf.length() > start && vBuf.charAt(start) == ' ')
        {
            vBuf.insert(start, "\\");
            start += 2;
        }
    }

    int endBuf = vBuf.length() - 1;

    while (endBuf >= 0 && vBuf.charAt(endBuf) == ' ')
    {
        vBuf.insert(endBuf, '\\');
        endBuf--;
    }

    return vBuf.toString();
}
项目:CryptMeme    文件:X509Name.java   
/**
 * Constructor from ASN1Sequence
 *
 * the principal will be a list of constructed sets, each containing an (OID, String) pair.
 * @deprecated use X500Name.getInstance()
 */
public X509Name(
    ASN1Sequence  seq)
{
    this.seq = seq;

    Enumeration e = seq.getObjects();

    while (e.hasMoreElements())
    {
        ASN1Set         set = ASN1Set.getInstance(((ASN1Encodable)e.nextElement()).toASN1Primitive());

        for (int i = 0; i < set.size(); i++) 
        {
               ASN1Sequence s = ASN1Sequence.getInstance(set.getObjectAt(i).toASN1Primitive());

               if (s.size() != 2)
               {
                   throw new IllegalArgumentException("badly sized pair");
               }

               ordering.addElement(ASN1ObjectIdentifier.getInstance(s.getObjectAt(0)));

               ASN1Encodable value = s.getObjectAt(1);
               if (value instanceof ASN1String && !(value instanceof DERUniversalString))
               {
                   String v = ((ASN1String)value).getString();
                   if (v.length() > 0 && v.charAt(0) == '#')
                   {
                       values.addElement("\\" + v);
                   }
                   else
                   {
                       values.addElement(v);
                   }
               }
               else
               {
                   try
                   {
                       values.addElement("#" + bytesToString(Hex.encode(value.toASN1Primitive().getEncoded(ASN1Encoding.DER))));
                   }
                   catch (IOException e1)
                   {
                       throw new IllegalArgumentException("cannot encode value");
                   }
               }
               added.addElement((i != 0) ? TRUE : FALSE);  // to allow earlier JDK compatibility
        }
    }
}
项目:CryptMeme    文件:DirectoryString.java   
private DirectoryString(
    DERUniversalString string)
{
    this.string = string;
}
项目:CryptMeme    文件:IETFUtils.java   
public static String valueToString(ASN1Encodable value)
{
    StringBuffer vBuf = new StringBuffer();

    if (value instanceof ASN1String && !(value instanceof DERUniversalString))
    {
        String v = ((ASN1String)value).getString();
        if (v.length() > 0 && v.charAt(0) == '#')
        {
            vBuf.append("\\" + v);
        }
        else
        {
            vBuf.append(v);
        }
    }
    else
    {
        try
        {
            vBuf.append("#" + bytesToString(Hex.encode(value.toASN1Primitive().getEncoded(ASN1Encoding.DER))));
        }
        catch (IOException e)
        {
            throw new IllegalArgumentException("Other value has no encoded form");
        }
    }

    int     end = vBuf.length();
    int     index = 0;

    if (vBuf.length() >= 2 && vBuf.charAt(0) == '\\' && vBuf.charAt(1) == '#')
    {
        index += 2;
    }

    while (index != end)
    {
        if ((vBuf.charAt(index) == ',')
           || (vBuf.charAt(index) == '"')
           || (vBuf.charAt(index) == '\\')
           || (vBuf.charAt(index) == '+')
           || (vBuf.charAt(index) == '=')
           || (vBuf.charAt(index) == '<')
           || (vBuf.charAt(index) == '>')
           || (vBuf.charAt(index) == ';'))
        {
            vBuf.insert(index, "\\");
            index++;
            end++;
        }

        index++;
    }

    int start = 0;
    if (vBuf.length() > 0)
    {
        while (vBuf.length() > start && vBuf.charAt(start) == ' ')
        {
            vBuf.insert(start, "\\");
            start += 2;
        }
    }

    int endBuf = vBuf.length() - 1;

    while (endBuf >= 0 && vBuf.charAt(endBuf) == ' ')
    {
        vBuf.insert(endBuf, '\\');
        endBuf--;
    }

    return vBuf.toString();
}
项目:nsi-dds    文件:ExtendedIETFUtils.java   
public static String valueToString(ASN1Encodable value)
{
    StringBuilder vBuf = new StringBuilder();

    if (value instanceof ASN1String && !(value instanceof DERUniversalString))
    {
        String v = ((ASN1String)value).getString();
        if (v.length() > 0 && v.charAt(0) == '#')
        {
            vBuf.append("\\");
            vBuf.append(v);
        }
        else
        {
            vBuf.append(v);
        }
    }
    else
    {
        try
        {
            vBuf.append("#");
            vBuf.append(bytesToString(Hex.encode(value.toASN1Primitive().getEncoded(ASN1Encoding.DER))));
        }
        catch (IOException e)
        {
            throw new IllegalArgumentException("Other value has no encoded form");
        }
    }

    int     end = vBuf.length();
    int     index = 0;

    if (vBuf.length() >= 2 && vBuf.charAt(0) == '\\' && vBuf.charAt(1) == '#')
    {
        index += 2;
    }

    while (index != end)
    {
        if ((vBuf.charAt(index) == ',')
           || (vBuf.charAt(index) == '"')
           || (vBuf.charAt(index) == '\\')
           || (vBuf.charAt(index) == '+')
           || (vBuf.charAt(index) == '=')
           || (vBuf.charAt(index) == '<')
           || (vBuf.charAt(index) == '>')
           || (vBuf.charAt(index) == ';'))
        {
            vBuf.insert(index, "\\");
            index++;
            end++;
        }

        index++;
    }

    int start = 0;
    if (vBuf.length() > 0)
    {
        while (vBuf.length() > start && vBuf.charAt(start) == ' ')
        {
            vBuf.insert(start, "\\");
            start += 2;
        }
    }

    int endBuf = vBuf.length() - 1;

    while (endBuf >= 0 && vBuf.charAt(endBuf) == ' ')
    {
        vBuf.insert(endBuf, '\\');
        endBuf--;
    }

    return vBuf.toString();
}
项目:irma_future_id    文件:X509Name.java   
/**
 * Constructor from ASN1Sequence
 *
 * the principal will be a list of constructed sets, each containing an (OID, String) pair.
 * @deprecated use X500Name.getInstance()
 */
public X509Name(
    ASN1Sequence  seq)
{
    this.seq = seq;

    Enumeration e = seq.getObjects();

    while (e.hasMoreElements())
    {
        ASN1Set         set = ASN1Set.getInstance(((ASN1Encodable)e.nextElement()).toASN1Primitive());

        for (int i = 0; i < set.size(); i++) 
        {
               ASN1Sequence s = ASN1Sequence.getInstance(set.getObjectAt(i).toASN1Primitive());

               if (s.size() != 2)
               {
                   throw new IllegalArgumentException("badly sized pair");
               }

               ordering.addElement(ASN1ObjectIdentifier.getInstance(s.getObjectAt(0)));

               ASN1Encodable value = s.getObjectAt(1);
               if (value instanceof ASN1String && !(value instanceof DERUniversalString))
               {
                   String v = ((ASN1String)value).getString();
                   if (v.length() > 0 && v.charAt(0) == '#')
                   {
                       values.addElement("\\" + v);
                   }
                   else
                   {
                       values.addElement(v);
                   }
               }
               else
               {
                   try
                   {
                       values.addElement("#" + bytesToString(Hex.encode(value.toASN1Primitive().getEncoded(ASN1Encoding.DER))));
                   }
                   catch (IOException e1)
                   {
                       throw new IllegalArgumentException("cannot encode value");
                   }
               }
               added.addElement((i != 0) ? TRUE : FALSE);  // to allow earlier JDK compatibility
        }
    }
}
项目:irma_future_id    文件:DirectoryString.java   
private DirectoryString(
    DERUniversalString string)
{
    this.string = string;
}
项目:irma_future_id    文件:IETFUtils.java   
public static String valueToString(ASN1Encodable value)
{
    StringBuffer vBuf = new StringBuffer();

    if (value instanceof ASN1String && !(value instanceof DERUniversalString))
    {
        String v = ((ASN1String)value).getString();
        if (v.length() > 0 && v.charAt(0) == '#')
        {
            vBuf.append("\\" + v);
        }
        else
        {
            vBuf.append(v);
        }
    }
    else
    {
        try
        {
            vBuf.append("#" + bytesToString(Hex.encode(value.toASN1Primitive().getEncoded(ASN1Encoding.DER))));
        }
        catch (IOException e)
        {
            throw new IllegalArgumentException("Other value has no encoded form");
        }
    }

    int     end = vBuf.length();
    int     index = 0;

    if (vBuf.length() >= 2 && vBuf.charAt(0) == '\\' && vBuf.charAt(1) == '#')
    {
        index += 2;
    }

    while (index != end)
    {
        if ((vBuf.charAt(index) == ',')
           || (vBuf.charAt(index) == '"')
           || (vBuf.charAt(index) == '\\')
           || (vBuf.charAt(index) == '+')
           || (vBuf.charAt(index) == '=')
           || (vBuf.charAt(index) == '<')
           || (vBuf.charAt(index) == '>')
           || (vBuf.charAt(index) == ';'))
        {
            vBuf.insert(index, "\\");
            index++;
            end++;
        }

        index++;
    }

    int start = 0;
    if (vBuf.length() > 0)
    {
        while (vBuf.charAt(start) == ' ')
        {
            vBuf.insert(start, "\\");
            start += 2;
        }
    }

    int endBuf = vBuf.length() - 1;

    while (endBuf >= 0 && vBuf.charAt(endBuf) == ' ')
    {
        vBuf.insert(endBuf, '\\');
        endBuf--;
    }

    return vBuf.toString();
}
项目:irma_future_id    文件:EqualsAndHashCodeTest.java   
public TestResult perform()
{
    byte[]    data = { 0, 1, 0, 1, 0, 0, 1 };

    ASN1Primitive    values[] = {
            new BERConstructedOctetString(data),
            new BERSequence(new DERPrintableString("hello world")),
            new BERSet(new DERPrintableString("hello world")),
            new BERTaggedObject(0, new DERPrintableString("hello world")),
            new DERApplicationSpecific(0, data),
            new DERBitString(data),
            new DERBMPString("hello world"),
            new DERBoolean(true),
            new DERBoolean(false),
            new DEREnumerated(100),
            new DERGeneralizedTime("20070315173729Z"),
            new DERGeneralString("hello world"),
            new DERIA5String("hello"),
            new DERInteger(1000),
            new DERNull(),
            new DERNumericString("123456"),
            new DERObjectIdentifier("1.1.1.10000.1"),
            new DEROctetString(data),
            new DERPrintableString("hello world"),
            new DERSequence(new DERPrintableString("hello world")),
            new DERSet(new DERPrintableString("hello world")),
            new DERT61String("hello world"),
            new DERTaggedObject(0, new DERPrintableString("hello world")),
            new DERUniversalString(data),
            new DERUTCTime(new Date()),
            new DERUTF8String("hello world"),
            new DERVisibleString("hello world")
        };

    try
    {
        ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
        ASN1OutputStream        aOut = new ASN1OutputStream(bOut);

        for (int i = 0; i != values.length; i++)
        {
            aOut.writeObject(values[i]);
        }

        ASN1Primitive[] readValues = new ASN1Primitive[values.length];

        ByteArrayInputStream    bIn = new ByteArrayInputStream(bOut.toByteArray());
        ASN1InputStream         aIn = new ASN1InputStream(bIn);

        for (int i = 0; i != values.length; i++)
        {
            ASN1Primitive o = aIn.readObject();
            if (!o.equals(values[i]))
            {
                return new SimpleTestResult(false, getName() + ": Failed equality test for " + o.getClass());
            }

            if (o.hashCode() != values[i].hashCode())
            {
                return new SimpleTestResult(false, getName() + ": Failed hashCode test for " + o.getClass());
            }
        }
    }
    catch (Exception e)
    {
        return new SimpleTestResult(false, getName() + ": Failed - exception " + e.toString(), e);
    }

    return new SimpleTestResult(true, getName() + ": Okay");
}
项目:bc-java    文件:X509Name.java   
/**
 * Constructor from ASN1Sequence
 *
 * the principal will be a list of constructed sets, each containing an (OID, String) pair.
 * @deprecated use X500Name.getInstance()
 */
public X509Name(
    ASN1Sequence  seq)
{
    this.seq = seq;

    Enumeration e = seq.getObjects();

    while (e.hasMoreElements())
    {
        ASN1Set         set = ASN1Set.getInstance(((ASN1Encodable)e.nextElement()).toASN1Primitive());

        for (int i = 0; i < set.size(); i++) 
        {
               ASN1Sequence s = ASN1Sequence.getInstance(set.getObjectAt(i).toASN1Primitive());

               if (s.size() != 2)
               {
                   throw new IllegalArgumentException("badly sized pair");
               }

               ordering.addElement(ASN1ObjectIdentifier.getInstance(s.getObjectAt(0)));

               ASN1Encodable value = s.getObjectAt(1);
               if (value instanceof ASN1String && !(value instanceof DERUniversalString))
               {
                   String v = ((ASN1String)value).getString();
                   if (v.length() > 0 && v.charAt(0) == '#')
                   {
                       values.addElement("\\" + v);
                   }
                   else
                   {
                       values.addElement(v);
                   }
               }
               else
               {
                   try
                   {
                       values.addElement("#" + bytesToString(Hex.encode(value.toASN1Primitive().getEncoded(ASN1Encoding.DER))));
                   }
                   catch (IOException e1)
                   {
                       throw new IllegalArgumentException("cannot encode value");
                   }
               }
               added.addElement((i != 0) ? TRUE : FALSE);  // to allow earlier JDK compatibility
        }
    }
}
项目:bc-java    文件:DirectoryString.java   
private DirectoryString(
    DERUniversalString string)
{
    this.string = string;
}
项目:bc-java    文件:IETFUtils.java   
public static String valueToString(ASN1Encodable value)
{
    StringBuffer vBuf = new StringBuffer();

    if (value instanceof ASN1String && !(value instanceof DERUniversalString))
    {
        String v = ((ASN1String)value).getString();
        if (v.length() > 0 && v.charAt(0) == '#')
        {
            vBuf.append("\\" + v);
        }
        else
        {
            vBuf.append(v);
        }
    }
    else
    {
        try
        {
            vBuf.append("#" + bytesToString(Hex.encode(value.toASN1Primitive().getEncoded(ASN1Encoding.DER))));
        }
        catch (IOException e)
        {
            throw new IllegalArgumentException("Other value has no encoded form");
        }
    }

    int     end = vBuf.length();
    int     index = 0;

    if (vBuf.length() >= 2 && vBuf.charAt(0) == '\\' && vBuf.charAt(1) == '#')
    {
        index += 2;
    }

    while (index != end)
    {
        if ((vBuf.charAt(index) == ',')
           || (vBuf.charAt(index) == '"')
           || (vBuf.charAt(index) == '\\')
           || (vBuf.charAt(index) == '+')
           || (vBuf.charAt(index) == '=')
           || (vBuf.charAt(index) == '<')
           || (vBuf.charAt(index) == '>')
           || (vBuf.charAt(index) == ';'))
        {
            vBuf.insert(index, "\\");
            index++;
            end++;
        }

        index++;
    }

    int start = 0;
    if (vBuf.length() > 0)
    {
        while (vBuf.charAt(start) == ' ')
        {
            vBuf.insert(start, "\\");
            start += 2;
        }
    }

    int endBuf = vBuf.length() - 1;

    while (endBuf >= 0 && vBuf.charAt(endBuf) == ' ')
    {
        vBuf.insert(endBuf, '\\');
        endBuf--;
    }

    return vBuf.toString();
}
项目:bc-java    文件:EqualsAndHashCodeTest.java   
public TestResult perform()
{
    byte[]    data = { 0, 1, 0, 1, 0, 0, 1 };

    ASN1Primitive    values[] = {
            new BERConstructedOctetString(data),
            new BERSequence(new DERPrintableString("hello world")),
            new BERSet(new DERPrintableString("hello world")),
            new BERTaggedObject(0, new DERPrintableString("hello world")),
            new DERApplicationSpecific(0, data),
            new DERBitString(data),
            new DERBMPString("hello world"),
            new DERBoolean(true),
            new DERBoolean(false),
            new DEREnumerated(100),
            new DERGeneralizedTime("20070315173729Z"),
            new DERGeneralString("hello world"),
            new DERIA5String("hello"),
            new DERInteger(1000),
            new DERNull(),
            new DERNumericString("123456"),
            new DERObjectIdentifier("1.1.1.10000.1"),
            new DEROctetString(data),
            new DERPrintableString("hello world"),
            new DERSequence(new DERPrintableString("hello world")),
            new DERSet(new DERPrintableString("hello world")),
            new DERT61String("hello world"),
            new DERTaggedObject(0, new DERPrintableString("hello world")),
            new DERUniversalString(data),
            new DERUTCTime(new Date()),
            new DERUTF8String("hello world"),
            new DERVisibleString("hello world")
        };

    try
    {
        ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
        ASN1OutputStream        aOut = new ASN1OutputStream(bOut);

        for (int i = 0; i != values.length; i++)
        {
            aOut.writeObject(values[i]);
        }

        ASN1Primitive[] readValues = new ASN1Primitive[values.length];

        ByteArrayInputStream    bIn = new ByteArrayInputStream(bOut.toByteArray());
        ASN1InputStream         aIn = new ASN1InputStream(bIn);

        for (int i = 0; i != values.length; i++)
        {
            ASN1Primitive o = aIn.readObject();
            if (!o.equals(values[i]))
            {
                return new SimpleTestResult(false, getName() + ": Failed equality test for " + o.getClass());
            }

            if (o.hashCode() != values[i].hashCode())
            {
                return new SimpleTestResult(false, getName() + ": Failed hashCode test for " + o.getClass());
            }
        }
    }
    catch (Exception e)
    {
        return new SimpleTestResult(false, getName() + ": Failed - exception " + e.toString(), e);
    }

    return new SimpleTestResult(true, getName() + ": Okay");
}