org.bouncycastle.asn1.BERTags Java Examples
The following examples show how to use
org.bouncycastle.asn1.BERTags.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Asn1StreamParser.java From xipki with Apache License 2.0 | 6 votes |
protected static Date readTime(MyInt bytesLen, BufferedInputStream instream, String name) throws IOException { int tag = markAndReadTag(instream); byte[] bytes = readBlock(instream, name); bytesLen.set(bytes.length); try { if (tag == BERTags.UTC_TIME) { return DERUTCTime.getInstance(bytes).getDate(); } else if (tag == BERTags.GENERALIZED_TIME) { return DERGeneralizedTime.getInstance(bytes).getDate(); } else { throw new IllegalArgumentException("invalid tag for " + name + ": " + tag); } } catch (ParseException ex) { throw new IllegalArgumentException("error parsing time", ex); } }
Example #2
Source File: ScepUtil.java From xipki with Apache License 2.0 | 6 votes |
public static Date getTime(Object obj) { if (obj instanceof byte[]) { byte[] encoded = (byte[]) obj; int tag = encoded[0] & 0xFF;; try { if (tag == BERTags.UTC_TIME) { return DERUTCTime.getInstance(encoded).getDate(); } else if (tag == BERTags.GENERALIZED_TIME) { return DERGeneralizedTime.getInstance(encoded).getDate(); } else { throw new IllegalArgumentException("invalid tag " + tag); } } catch (ParseException ex) { throw new IllegalArgumentException("error parsing time", ex); } } else if (obj instanceof Time) { return ((Time) obj).getDate(); } else if (obj instanceof org.bouncycastle.asn1.cms.Time) { return ((org.bouncycastle.asn1.cms.Time) obj).getDate(); } else { return Time.getInstance(obj).getDate(); } }
Example #3
Source File: XAdESWithPemEncodedCrlTest.java From dss with GNU Lesser General Public License v2.1 | 4 votes |
private boolean isDerEncoded(byte[] binaries) { return binaries != null && binaries.length > 0 && (BERTags.SEQUENCE | BERTags.CONSTRUCTED) == binaries[0]; }
Example #4
Source File: CAdESWithPemEncodedCrlTest.java From dss with GNU Lesser General Public License v2.1 | 4 votes |
private boolean isDerEncoded(byte[] binaries) { return binaries != null && binaries.length > 0 && (BERTags.SEQUENCE | BERTags.CONSTRUCTED) == binaries[0]; }
Example #5
Source File: AbstractCRLUtils.java From dss with GNU Lesser General Public License v2.1 | 4 votes |
private boolean isDerEncoded(byte first) { return (BERTags.SEQUENCE | BERTags.CONSTRUCTED) == first; }
Example #6
Source File: PAdESWithPemEncodedCrlTest.java From dss with GNU Lesser General Public License v2.1 | 4 votes |
private boolean isDerEncoded(byte[] binaries) { return binaries != null && binaries.length > 0 && (BERTags.SEQUENCE | BERTags.CONSTRUCTED) == binaries[0]; }
Example #7
Source File: DSSASN1Utils.java From dss with GNU Lesser General Public License v2.1 | 4 votes |
public static boolean isASN1SequenceTag(byte tagByte) { // BERTags.SEQUENCE | BERTags.CONSTRUCTED = 0x30 return (BERTags.SEQUENCE | BERTags.CONSTRUCTED) == tagByte; }
Example #8
Source File: CRLParser.java From dss with GNU Lesser General Public License v2.1 | 4 votes |
/** * This method allows to parse the CRL and return the revocation data for a given serial number * * @param s * an InputStream with the CRL * @param serialNumber * the certificate's serial number * @return the X509CRLEntry with the revocation date, the reason,... or null if the serial number is not present in * the CRL * @throws IOException */ public X509CRLEntry retrieveRevocationInfo(InputStream s, BigInteger serialNumber) throws IOException { // Skip CertificateList Sequence info consumeTagIntro(s); // Read TBSCertList Sequence consumeTagIntro(s); // Skip all before mandatory thisUpdate int tag = -1; int tagNo = BERTags.NULL; int length = -1; do { tag = DERUtil.readTag(s); tagNo = DERUtil.readTagNumber(s, tag); length = DERUtil.readLength(s); skip(s, length); } while (!isDate(tagNo)); tag = DERUtil.readTag(s); tagNo = DERUtil.readTagNumber(s, tag); length = DERUtil.readLength(s); // TBSCertList -> nextUpdate (optional) if (isDate(tagNo)) { skip(s, length); tag = DERUtil.readTag(s); tagNo = DERUtil.readTagNumber(s, tag); length = DERUtil.readLength(s); } while (tagNo == BERTags.SEQUENCE) { tag = DERUtil.readTag(s); if (tag < 0) { // EOF return null; } tagNo = DERUtil.readTagNumber(s, tag); length = DERUtil.readLength(s); if (tagNo == BERTags.SEQUENCE) { byte[] entryArray = readNbBytes(s, length); try (InputStream is = new ByteArrayInputStream(entryArray)) { int entryTag = DERUtil.readTag(is); int entryTagNo = DERUtil.readTagNumber(is, entryTag); int entryLength = DERUtil.readLength(is); // SerialNumber if (BERTags.INTEGER == entryTagNo) { ASN1Integer asn1SerialNumber = rebuildASN1Integer(readNbBytes(is, entryLength)); if (serialNumber.equals(asn1SerialNumber.getValue())) { ASN1Sequence asn1Sequence = rebuildASN1Sequence(entryArray); CRLEntry crlEntry = CRLEntry.getInstance(asn1Sequence); return new X509CRLEntryObject(crlEntry); } } } } else { LOG.debug("Should only contain SEQUENCEs : tagNo = {} (ignored)", tagNo); skip(s, length); } } return null; }
Example #9
Source File: CRLParser.java From dss with GNU Lesser General Public License v2.1 | 4 votes |
private boolean isDate(int tagNo) { return (tagNo == BERTags.UTC_TIME) || (tagNo == BERTags.GENERALIZED_TIME); }
Example #10
Source File: CRLParser.java From dss with GNU Lesser General Public License v2.1 | 4 votes |
private ASN1Sequence rebuildASN1Sequence(byte[] array) throws IOException { // BERTags.SEQUENCE | BERTags.CONSTRUCTED = 0x30 return (ASN1Sequence) rebuildASN1Primitive((BERTags.SEQUENCE | BERTags.CONSTRUCTED), array); }
Example #11
Source File: CRLParser.java From dss with GNU Lesser General Public License v2.1 | 4 votes |
private ASN1BitString rebuildASN1BitString(byte[] array) throws IOException { return (ASN1BitString) rebuildASN1Primitive(BERTags.BIT_STRING, array); }
Example #12
Source File: CRLParser.java From dss with GNU Lesser General Public License v2.1 | 4 votes |
private ASN1Integer rebuildASN1Integer(byte[] array) throws IOException { return (ASN1Integer) rebuildASN1Primitive(BERTags.INTEGER, array); }