/** * Constructor from given details. * <p> * If <code>digestedObjectType</code> is not {@link #publicKeyCert} or * {@link #publicKey} <code>otherObjectTypeID</code> must be given, * otherwise it is ignored. * * @param digestedObjectType The digest object type. * @param otherObjectTypeID The object type ID for * <code>otherObjectDigest</code>. * @param digestAlgorithm The algorithm identifier for the hash. * @param objectDigest The hash value. */ public ObjectDigestInfo( int digestedObjectType, ASN1ObjectIdentifier otherObjectTypeID, AlgorithmIdentifier digestAlgorithm, byte[] objectDigest) { this.digestedObjectType = new ASN1Enumerated(digestedObjectType); if (digestedObjectType == otherObjectDigest) { this.otherObjectTypeID = otherObjectTypeID; } this.digestAlgorithm = digestAlgorithm; this.objectDigest = new DERBitString(objectDigest); }
private ObjectDigestInfo( ASN1Sequence seq) { if (seq.size() > 4 || seq.size() < 3) { throw new IllegalArgumentException("Bad sequence size: " + seq.size()); } digestedObjectType = ASN1Enumerated.getInstance(seq.getObjectAt(0)); int offset = 0; if (seq.size() == 4) { otherObjectTypeID = ASN1ObjectIdentifier.getInstance(seq.getObjectAt(1)); offset++; } digestAlgorithm = AlgorithmIdentifier.getInstance(seq.getObjectAt(1 + offset)); objectDigest = DERBitString.getInstance(seq.getObjectAt(2 + offset)); }
public static NodeStatusRequestMessage getInstance(Object o) { if (o instanceof NodeStatusRequestMessage) { return (NodeStatusRequestMessage)o; } else if (o instanceof Type) { return new NodeStatusRequestMessage((Type)o); } else if (o instanceof ASN1Sequence) { ASN1Sequence seq = (ASN1Sequence)o; ASN1Enumerated eTYpe = (ASN1Enumerated)seq.getObjectAt(0); Type type = Type.values()[eTYpe.getValue().intValue()]; NodeStatusRequestMessage out = new NodeStatusRequestMessage(type); return out; } throw new IllegalArgumentException("Can not convert from " + o.getClass().getName() + " to " + NodeStatusRequestMessage.class.getName() + " instance"); }
public static CRLReason getInstance(Object o) { if (o instanceof CRLReason) { return (CRLReason)o; } else if (o != null) { return lookup(ASN1Enumerated.getInstance(o).getValue().intValue()); } return null; }
public static ServiceType getInstance(Object obj) { if (obj instanceof ServiceType) { return (ServiceType)obj; } else if (obj != null) { return new ServiceType(ASN1Enumerated.getInstance(obj)); } return null; }
public static OCSPResponseStatus getInstance( Object obj) { if (obj instanceof OCSPResponseStatus) { return (OCSPResponseStatus)obj; } else if (obj != null) { return new OCSPResponseStatus(ASN1Enumerated.getInstance(obj)); } return null; }
public SpnegoTargToken(byte[] token) throws DecodingException { ASN1InputStream stream = new ASN1InputStream(new ByteArrayInputStream(token)); ASN1TaggedObject tagged; try { tagged = DecodingUtil.as(ASN1TaggedObject.class, stream); } catch(IOException e) { throw new DecodingException("spnego.token.malformed", null, e); } ASN1Sequence sequence = ASN1Sequence.getInstance(tagged, true); Enumeration<?> fields = sequence.getObjects(); while(fields.hasMoreElements()) { tagged = DecodingUtil.as(ASN1TaggedObject.class, fields); switch (tagged.getTagNo()) { case 0: ASN1Enumerated enumerated = DEREnumerated.getInstance(tagged, true); result = enumerated.getValue().intValue(); break; case 1: ASN1ObjectIdentifier mechanismOid = DERObjectIdentifier.getInstance(tagged, true); mechanism = mechanismOid.getId(); break; case 2: ASN1OctetString mechanismTokenString = ASN1OctetString.getInstance(tagged, true); mechanismToken = mechanismTokenString.getOctets(); break; case 3: ASN1OctetString mechanismListString = ASN1OctetString.getInstance(tagged, true); mechanismList = mechanismListString.getOctets(); break; default: Object[] args = new Object[]{tagged.getTagNo()}; throw new DecodingException("spnego.field.invalid", args, null); } } }
private RevokedInfo( ASN1Sequence seq) { this.revocationTime = ASN1GeneralizedTime.getInstance(seq.getObjectAt(0)); if (seq.size() > 1) { this.revocationReason = CRLReason.getInstance(ASN1Enumerated.getInstance( (ASN1TaggedObject)seq.getObjectAt(1), true)); } }
public static int getIntegerFromAsn1(ASN1Encodable asn1Value) throws Exception { if (asn1Value instanceof ASN1Integer) { return KeyAttestationExample.bigIntegerToInt(((ASN1Integer) asn1Value).getValue()); } else if (asn1Value instanceof ASN1Enumerated) { return KeyAttestationExample.bigIntegerToInt(((ASN1Enumerated) asn1Value).getValue()); } else { throw new Exception("Integer value expected; found " + asn1Value.getClass().getName() + " instead."); } }
@Override public byte[] toByteArray () { try { ByteArrayOutputStream collector = new ByteArrayOutputStream(); DEROutputStream der = new DEROutputStream(collector); ASN1EncodableVector fields = new ASN1EncodableVector(); int res = getResult(); if ( res != UNSPECIFIED_RESULT ) { fields.add(new DERTaggedObject(true, 0, new ASN1Enumerated(res))); } ASN1ObjectIdentifier mech = getMechanism(); if ( mech != null ) { fields.add(new DERTaggedObject(true, 1, mech)); } byte[] mechanismToken = getMechanismToken(); if ( mechanismToken != null ) { fields.add(new DERTaggedObject(true, 2, new DEROctetString(mechanismToken))); } byte[] mechanismListMIC = getMechanismListMIC(); if ( mechanismListMIC != null ) { fields.add(new DERTaggedObject(true, 3, new DEROctetString(mechanismListMIC))); } der.writeObject(new DERTaggedObject(true, 1, new DERSequence(fields))); return collector.toByteArray(); } catch ( IOException ex ) { throw new IllegalStateException(ex.getMessage()); } }
@Override protected void parse ( byte[] token ) throws IOException { try ( ASN1InputStream der = new ASN1InputStream(token) ) { ASN1TaggedObject tagged = (ASN1TaggedObject) der.readObject(); ASN1Sequence sequence = ASN1Sequence.getInstance(tagged, true); Enumeration<?> fields = sequence.getObjects(); while ( fields.hasMoreElements() ) { tagged = (ASN1TaggedObject) fields.nextElement(); switch ( tagged.getTagNo() ) { case 0: ASN1Enumerated enumerated = ASN1Enumerated.getInstance(tagged, true); setResult(enumerated.getValue().intValue()); break; case 1: setMechanism(ASN1ObjectIdentifier.getInstance(tagged, true)); break; case 2: ASN1OctetString mechanismToken = ASN1OctetString.getInstance(tagged, true); setMechanismToken(mechanismToken.getOctets()); break; case 3: ASN1OctetString mechanismListMIC = ASN1OctetString.getInstance(tagged, true); setMechanismListMIC(mechanismListMIC.getOctets()); break; default: throw new IOException("Malformed token field."); } } } }
/** * Get dump of the supplied ASN.1 object. * * @param asn1Object * ASN.1 object * @return Dump of object * @throws Asn1Exception * A problem was encountered getting the ASN.1 dump * @throws IOException * If an I/O problem occurred */ public String dump(ASN1Primitive asn1Object) throws Asn1Exception, IOException { // Get dump of the supplied ASN.1 object incrementing the indent level of the output try { indentLevel++; if (asn1Object instanceof DERBitString) { // special case of ASN1String return dumpBitString((DERBitString) asn1Object); } else if (asn1Object instanceof ASN1String) { return dumpString((ASN1String) asn1Object); } else if (asn1Object instanceof ASN1UTCTime) { return dumpUTCTime((ASN1UTCTime) asn1Object); } else if (asn1Object instanceof ASN1GeneralizedTime) { return dumpGeneralizedTime((ASN1GeneralizedTime) asn1Object); } else if (asn1Object instanceof ASN1Sequence || asn1Object instanceof ASN1Set ) { return dumpSetOrSequence(asn1Object); } else if (asn1Object instanceof ASN1TaggedObject) { return dumpTaggedObject((ASN1TaggedObject) asn1Object); } else if (asn1Object instanceof ASN1Boolean) { return dumpBoolean((ASN1Boolean) asn1Object); } else if (asn1Object instanceof ASN1Enumerated) { return dumpEnumerated((ASN1Enumerated) asn1Object); } else if (asn1Object instanceof ASN1Integer) { return dumpInteger((ASN1Integer) asn1Object); } else if (asn1Object instanceof ASN1Null) { return dumpNull((ASN1Null) asn1Object); } else if (asn1Object instanceof ASN1ObjectIdentifier) { return dumpObjectIdentifier((ASN1ObjectIdentifier) asn1Object); } else if (asn1Object instanceof ASN1OctetString) { return dumpOctetString((ASN1OctetString) asn1Object); } else { throw new Asn1Exception("Unknown ASN.1 object: " + asn1Object.toString()); } } finally { if (true) { indentLevel--; } } }
private String dumpEnumerated(ASN1Enumerated asn1Enumerated) { StringBuilder sb = new StringBuilder(); sb.append(indentSequence.toString(indentLevel)); sb.append("ENUMERATED="); sb.append(asn1Enumerated.getValue()); sb.append(NEWLINE); return sb.toString(); }
public static ReplyStatus getInstance(Object obj) { if (obj instanceof ReplyStatus) { return (ReplyStatus) obj; } else if (obj != null) { return new ReplyStatus(ASN1Enumerated.getInstance(obj)); } return null; }
public static CVStatusCode getInstance(Object obj) { if (obj instanceof CVStatusCode) { return (CVStatusCode) obj; } else if (obj != null) { return new CVStatusCode(ASN1Enumerated.getInstance(obj)); } return null; }
public static ResponseTypes getInstance(Object obj) { if (obj instanceof ResponseTypes) { return (ResponseTypes) obj; } else if (obj != null) { return new ResponseTypes(ASN1Enumerated.getInstance(obj)); } return null; }