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

项目:AcademicTorrents-Downloader    文件:RoleSyntax.java   
/**
 * Gets the role authority as a <code>String[]</code> object.
 * @return the role authority of this RoleSyntax represented as a
 * <code>String[]</code> array.
 */
public String[] getRoleAuthorityAsString() 
{
    if(roleAuthority == null) 
    {
        return new String[0];
    }

    GeneralName[] names = roleAuthority.getNames();
    String[] namesString = new String[names.length];
    for(int i = 0; i < names.length; i++) 
    {
        DEREncodable value = names[i].getName();
        if(value instanceof DERString)
        {
            namesString[i] = ((DERString)value).getString();
        }
        else
        {
            namesString[i] = value.toString();
        }
    }
    return namesString;
}
项目:AcademicTorrents-Downloader    文件:DisplayText.java   
public static DisplayText getInstance(Object de) 
{
   if (de instanceof DERString)
   {
       return new DisplayText((DERString)de);
   }
   else if (de instanceof DisplayText)
   {
       return (DisplayText)de;
   }

   throw new IllegalArgumentException("illegal object in getInstance");
}
项目:AcademicTorrents-Downloader    文件:RoleSyntax.java   
/**
 * Constructor.
 * @param roleAuthority the role authority of this RoleSyntax.
 * @param roleName    the role name of this RoleSyntax.
 */
public RoleSyntax(
    GeneralNames roleAuthority,
    GeneralName roleName)
{
    if(roleName == null || 
            roleName.getTagNo() != GeneralName.uniformResourceIdentifier ||
            ((DERString)roleName.getName()).getString().equals(""))
    {
        throw new IllegalArgumentException("the role name MUST be non empty and MUST " +
                "use the URI option of GeneralName");
    }
    this.roleAuthority = roleAuthority;
    this.roleName = roleName;
}
项目:AcademicTorrents-Downloader    文件:RoleSyntax.java   
/**
 * Gets the role name as a <code>java.lang.String</code> object.
 * @return    the role name of this RoleSyntax represented as a 
 * <code>java.lang.String</code> object.
 */
public String getRoleNameAsString()
{
    DERString str = (DERString)this.roleName.getName();

    return str.getString();
}
项目:AcademicTorrents-Downloader    文件:X509Name.java   
/**
 * Constructor from ASN1Sequence
 *
 * the principal will be a list of constructed sets, each containing an (OID, String) pair.
 */
public X509Name(
    ASN1Sequence  seq)
{
    this.seq = seq;

    Enumeration e = seq.getObjects();

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

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

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

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

               DEREncodable value = s.getObjectAt(1);
               if (value instanceof DERString)
               {
                   values.addElement(((DERString)value).getString());
               }
               else
               {
                   values.addElement("#" + bytesToString(Hex.encode(value.getDERObject().getDEREncoded())));
               }
               added.addElement((i != 0) ? TRUE : FALSE);  // to allow earlier JDK compatibility
        }
    }
}
项目:alien-ofelia-conet-ccnx    文件:CryptoUtil.java   
/**
* Helper method to pull SubjectAlternativeNames from a certificate. BouncyCastle has
* one of these, but it isn't included on all platforms. We get one by default from X509Certificate
* but it returns us a collection of ? and we can't ever know what the ? is because we might
* get a different impl class on different platforms. So we have to roll our own.
* 
* We filter the general names down to ones we can handle.
* @param certificate
* @return
* @throws IOException 
* @throws CertificateEncodingException 
*/
  public static ArrayList<Tuple<Integer, String>> getSubjectAlternativeNames(X509Certificate certificate)
        throws IOException, CertificateEncodingException {        

    byte[] encodedExtension = certificate.getExtensionValue(X509Extensions.SubjectAlternativeName.getId());

    ArrayList<Tuple<Integer, String>> list = new ArrayList<Tuple<Integer, String>>();

    if (null == encodedExtension) {
        return list;
    }

// content of extension is wrapped in a DEROctetString
DEROctetString content = (DEROctetString)CryptoUtil.decode(encodedExtension);
byte [] encapsulatedOctetString = content.getOctets();

ASN1InputStream aIn = new ASN1InputStream(encapsulatedOctetString);
ASN1Encodable decodedObject = (ASN1Encodable)aIn.readObject();
ASN1Sequence sequence = (ASN1Sequence)decodedObject.getDERObject();

      Integer tag;
      GeneralName generalName;

      Enumeration<?> it = sequence.getObjects();
      while (it.hasMoreElements()) {
        generalName = GeneralName.getInstance(it.nextElement());
        tag = generalName.getTagNo();

        switch (tag) {
        case GeneralName.dNSName:
          case GeneralName.rfc822Name:
          case GeneralName.uniformResourceIdentifier:
            list.add(new Tuple<Integer,String>(tag, ((DERString)generalName.getName()).getString()));
          default:
            // ignore other types
        }
      }
      return list;
  }
项目:cagrid-general    文件:X509NameHelper.java   
private static String toString(ASN1Sequence seq) {
if (seq == null) {
    return null;
}

Enumeration e = seq.getObjects();
StringBuffer buf = new StringBuffer();
       while (e.hasMoreElements()) {
           ASN1Set set = (ASN1Set)e.nextElement();
    Enumeration ee = set.getObjects();
    buf.append('/');
    while (ee.hasMoreElements()) {
    ASN1Sequence s = (ASN1Sequence)ee.nextElement();
    DERObjectIdentifier oid = (DERObjectIdentifier)s.getObjectAt(0);
    String sym = (String)X509Name.OIDLookUp.get(oid);
    if (sym == null) {
        buf.append(oid.getId());
    } else {
        buf.append(sym);
    }
    buf.append('=');
    buf.append( ((DERString)s.getObjectAt(1)).getString());
    if (ee.hasMoreElements()) {
        buf.append('+');
    }
    }
}

return buf.toString();
   }
项目:AcademicTorrents-Downloader    文件:DisplayText.java   
/**
 * Creates a new <code>DisplayText</code> instance.
 * <p>Useful when reading back a <code>DisplayText</code> class
 * from it's ASN1Encodable/DEREncodable form. 
 *
 * @param de a <code>DEREncodable</code> instance. 
 */
public DisplayText(DERString de)
{
   contents = de;
}