@Override public void getChoiceLength(ASN1Choice choice) { int i = choice.getIndex(content); content = choice.getObjectToEncode(content); Object[] values = new Object[] { choice.type[i], content }; push(null, values); choice.type[i].setEncodingContent(this); // in case if we get content bytes while getting its length // FIXME what about remove it: need redesign values[1] = content; }
public final void verify(InputStream in) throws IOException { DerInputStream decoder = new DerInputStream(in); decoder.setVerify(); decode(decoder); }
/** * Decodes ASN.1 Octetstring type */ public void readOctetString() throws IOException { if (tag == ASN1Constants.TAG_OCTETSTRING) { readContent(); } else if (tag == ASN1Constants.TAG_C_OCTETSTRING) { throw new ASN1Exception("Decoding constructed ASN.1 octet string type is not supported"); } else { throw expected("octetstring"); } }
@Override public void getExplicitLength(ASN1Explicit explicit) { Object[] values = new Object[1]; int[] compLens = new int[1]; values[0] = content; push(compLens, values); explicit.type.setEncodingContent(this); // in case if we get content bytes while getting its length // FIXME what about remove it: need redesign values[0] = content; compLens[0] = length; length = explicit.type.getEncodedLength(this); }
public void encodeASN(BerOutputStream out) { out.encodeTag(constrId); encodeContent(out); } }
public Object decode(BerInputStream in) throws IOException { in.readEnumerated(); if (in.isVerify) { return null; } return getDecodedObject(in); }
@Override public Object getDecodedObject(BerInputStream in) throws IOException { // first - decoded octet string, // second - raw encoding of octet string return new Object[] {super.getDecodedObject(in), in.getEncoded()}; } }
public Object decode(BerInputStream in) throws IOException { in.readGeneralizedTime(); if (in.isVerify) { return null; } return getDecodedObject(in); }
/** * Decodes ASN.1 Set type */ public void readSet(ASN1Set set) throws IOException { if (tag != ASN1Constants.TAG_C_SET) { throw expected("set"); } throw new ASN1Exception("Decoding ASN.1 Set type is not supported"); }
public void readGeneralizedTime() throws IOException { if (tag == ASN1Constants.TAG_C_GENERALIZEDTIME) { // It is a string type and it can be encoded as primitive or constructed. throw new ASN1Exception("ASN.1 GeneralizedTime: constructed identifier at [" + tagOffset + "]. Not valid for DER."); } super.readGeneralizedTime(); } }
public Object decode(BerInputStream in) throws IOException { in.readInteger(); if (in.isVerify) { return null; } return getDecodedObject(in); }
public void encodeASN(BerOutputStream out) { //FIXME need another way for specifying identifier to be encoded if (taggingType == TAGGING_CONSTRUCTED) { out.encodeTag(constrId); } else { out.encodeTag(id); } encodeContent(out); }
public Object decode(BerInputStream in) throws IOException { // only read content, doesn't check it in.readContent(); if (in.isVerify) { return null; } return getDecodedObject(in); }
public Object getDecodedObject(BerInputStream in) throws IOException { int[] oid = (int[]) super.getDecodedObject(in); return ObjectIdentifier.toString(oid); } });
@Override public Object decode(BerInputStream in) throws IOException { in.readUTCTime(); if (in.isVerify) { return null; } return getDecodedObject(in); }
public void readString(ASN1StringType type) throws IOException { if (tag == type.constrId) { throw new ASN1Exception("ASN.1 string: constructed identifier at [" + tagOffset + "]. Not valid for DER."); } super.readString(type); }
public Object decode(BerInputStream in) throws IOException { in.readSequenceOf(this); if (in.isVerify) { return null; } return getDecodedObject(in); }
public Object decode(BerInputStream in) throws IOException { in.readSetOf(this); if (in.isVerify) { return null; } return getDecodedObject(in); }
public int next() throws IOException { int tag = super.next(); if (length == INDEFINIT_LENGTH) { throw new ASN1Exception("DER: only definite length encoding MUST be used"); } // FIXME add check: length encoding uses minimum number of octets return tag; }
public final void verify(byte[] encoded) throws IOException { DerInputStream decoder = new DerInputStream(encoded); decoder.setVerify(); decode(decoder); }