List of usage examples for org.bouncycastle.asn1.x509 Extensions getEncoded
public byte[] getEncoded(String encoding) throws IOException
From source file:com.guardtime.asn1.CertToken.java
License:Apache License
/** * Class constructor./*from ww w . j a v a2 s . c om*/ * * @param obj ASN.1 representation of certification token. */ CertToken(ASN1Encodable obj) throws Asn1FormatException { try { certToken = Asn1CertToken.getInstance(obj); version = certToken.getVersion().getValue().intValue(); if (version != VERSION) { throw new Asn1FormatException("invalid cert token version: " + version); } history = certToken.getHistory().getOctets(); publishedData = new PublishedData(certToken.getPublishedData()); ASN1Set pubRefs = certToken.getPubReference(); if (pubRefs != null) { pubReferences = new ArrayList(); Enumeration e = pubRefs.getObjects(); while (e.hasMoreElements()) { Object nextElement = e.nextElement(); if (!(nextElement instanceof DERNull)) { pubReferences.add(((ASN1OctetString) nextElement).getOctets()); } } } Extensions exts = certToken.getExtensions(); if (exts != null) { // check for critical extensions Asn1Util.checkExtensions(exts); extensions = exts.getEncoded(ASN1Encoding.DER); } } catch (Asn1FormatException e) { throw e; } catch (Exception e) { throw new Asn1FormatException("cert token has invalid format", e); } }
From source file:com.guardtime.asn1.TstInfo.java
License:Apache License
/** * Class constructor./*from w w w .j ava 2 s . c o m*/ * * @param obj ASN.1 representation of TST info. * * @throws Asn1FormatException if provided ASN.1 object has invalid format. */ TstInfo(ASN1Encodable obj) throws Asn1FormatException { try { tstInfo = TSTInfo.getInstance(obj); // Extract and check version BigInteger ver = tstInfo.getVersion().getValue(); if (!ver.equals(BigInteger.valueOf(VERSION))) { throw new Asn1FormatException("invalid TST info version: " + ver); } version = ver.intValue(); // Extract policy policy = tstInfo.getPolicy().getId(); // Extract message imprint messageImprint = new MessageImprint(tstInfo.getMessageImprint().toASN1Primitive()); // Extract serial number // // As `DERInteger` can be constructed out of `ASN1OctetString` // without any error, here we have no option to determine // if the serial number is actually an INTEGER or OCTET STRING. // // Possible solutions is to rewrite BouncyCastle `TSTInfo` class // adding more strict checks. serialNumber = tstInfo.getSerialNumber().getValue(); // Extract request time // // Current BouncyCastle implementation can parse the time string // that does not omit trailing zeros in second fraction part. // RFC 3161 requires that such time string is labeled invalid. genTime = tstInfo.getGenTime().getDate(); // Extract optional fields ASN1Encodable acc = tstInfo.getAccuracy(); accuracy = ((acc == null) ? null : new Accuracy(acc.toASN1Primitive())); ASN1Boolean ord = tstInfo.getOrdering(); ordering = (ord != null && ord.isTrue()); ASN1Integer nnc = tstInfo.getNonce(); nonce = ((nnc == null) ? null : nnc.getValue()); GeneralName tsaName = tstInfo.getTsa(); tsa = ((tsaName == null) ? null : tsaName.toString()); Extensions exts = tstInfo.getExtensions(); if (exts != null) { // check for critical extensions Asn1Util.checkExtensions(exts); extensions = exts.getEncoded(ASN1Encoding.DER); } } catch (Asn1FormatException e) { throw e; } catch (Exception e) { throw new Asn1FormatException("TST info has invalid format", e); } }