Example usage for org.bouncycastle.asn1.cmp OOBCertHash getInstance

List of usage examples for org.bouncycastle.asn1.cmp OOBCertHash getInstance

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.cmp OOBCertHash getInstance.

Prototype

public static OOBCertHash getInstance(Object o) 

Source Link

Usage

From source file:org.opensc.pkcs15.asn1.attr.CommonCertificateAttributes.java

License:Apache License

/**
 * @param obj The ASN.1 object to decode.
 * @return An instance of CommonObjectAttributes.
 *//*from   w  w w.j a  va2  s  .c om*/
public static CommonCertificateAttributes getInstance(Object obj) {
    if (obj instanceof CommonCertificateAttributes)
        return (CommonCertificateAttributes) obj;

    if (obj instanceof ASN1Sequence) {
        ASN1Sequence seq = (ASN1Sequence) obj;

        Enumeration<Object> objs = seq.getObjects();

        CommonCertificateAttributes ret = new CommonCertificateAttributes();

        while (objs.hasMoreElements()) {

            Object o = objs.nextElement();

            if (o instanceof ASN1OctetString) {
                ret.setID((ASN1OctetString) o);
            } else if (o instanceof DERBoolean) {
                ret.setAuthority(((DERBoolean) o).isTrue());
            } else if (o instanceof ASN1Sequence) {
                ret.setIdentifier(KeyIdentifier.getInstance(o));
            } else if (o instanceof ASN1TaggedObject) {

                ASN1TaggedObject to = (ASN1TaggedObject) o;

                switch (to.getTagNo()) {
                case 0:
                    ret.setCertHash(OOBCertHash.getInstance(to.getObject()));
                    break;
                case 1:
                    ret.setTrustedUsage(Usage.getInstance(to.getObject()));
                    break;
                case 2:
                    ret.setIdentifiers(KeyIdentifiers.getInstance(to.getObject()));
                    break;
                case 3:
                    ret.setImplicitTrust(DERBoolean.getInstance(to.getObject()).isTrue());
                    break;

                default:
                    throw new IllegalArgumentException("Invalid member tag [" + to.getTagNo()
                            + "] in member of CommonCertificateAttributes ASN.1 SEQUENCE.");
                }

            } else
                throw new IllegalArgumentException(
                        "Invalid member [" + o + "] in CommonCertificateAttributes ASN.1 SEQUENCE.");
        }

        return ret;
    }

    throw new IllegalArgumentException("CommonCertificateAttributes must be encoded as an ASN.1 SEQUENCE.");
}