use of com.unboundid.asn1.ASN1GeneralizedTime in project attestation by TokenScript.
the class ChequeDecoder method decode.
@Override
public Cheque decode(byte[] encoding) throws IOException {
ASN1InputStream input = null;
try {
input = new ASN1InputStream(encoding);
ASN1Sequence asn1 = ASN1Sequence.getInstance(input.readObject());
ASN1Sequence cheque = ASN1Sequence.getInstance(asn1.getObjectAt(0));
long amount = (ASN1Integer.getInstance(cheque.getObjectAt(0))).getValue().longValueExact();
ASN1Sequence validity = ASN1Sequence.getInstance(cheque.getObjectAt(1));
ASN1GeneralizedTime notValidBeforeEnc = ASN1GeneralizedTime.getInstance(validity.getObjectAt(0));
ASN1GeneralizedTime notValidAfterEnc = ASN1GeneralizedTime.getInstance(validity.getObjectAt(1));
long notValidBefore, notValidAfter;
try {
notValidBefore = notValidBeforeEnc.getDate().getTime();
notValidAfter = notValidAfterEnc.getDate().getTime();
} catch (ParseException e) {
throw ExceptionUtil.throwException(logger, new IOException("Validity is not encoded properly"));
}
byte[] commitment = (ASN1OctetString.getInstance(cheque.getObjectAt(2))).getOctets();
AsymmetricKeyParameter publicKey = SignatureUtility.restoreDefaultKey(DERBitString.getInstance(asn1.getObjectAt(1)).getEncoded());
// Verify signature
byte[] signature = DERBitString.getInstance(asn1.getObjectAt(2)).getBytes();
return new Cheque(commitment, amount, notValidBefore, notValidAfter, signature, publicKey);
} finally {
input.close();
}
}
Aggregations