@Test(expected=ASN1Exception.class) public void testEncodeObjectIdentifierInvalidSecondComponent() throws Exception { DEREncoder encoder = new DEREncoder(); encoder.encodeObjectIdentifier("0.50"); }
@Override public void encodeObjectIdentifier(String objectIdentifier) throws ASN1Exception { if (objectIdentifier == null || objectIdentifier.length() == 0) { throw log.asnOidMustHaveAtLeast2Components(); } int len = objectIdentifier.length(); int offs = 0; int idx = 0; long t = 0L; char c; int numComponents = 0; int first = -1; ByteStringBuilder contents = new ByteStringBuilder(); a: for (;;) { c = objectIdentifier.charAt(offs + idx ++); if (Character.isDigit(c)) { int digit = Character.digit(c, 10); if (t > LARGEST_UNSHIFTED_LONG) { BigInteger bi = BigInteger.valueOf(t).multiply(BigInteger.TEN).add(digits[digit]); t = 0L; for (;;) { c = objectIdentifier.charAt(offs + idx ++); if (Character.isDigit(c)) { digit = Character.digit(c, 10); bi = bi.multiply(BigInteger.TEN).add(digits[digit]); } else if (c == '.') { if (numComponents == 0) { first = validateFirstOIDComponent(bi); } else { encodeOIDComponent(bi, contents, numComponents, first); } numComponents++; continue a; } else { throw log.asnInvalidOidCharacter(); } if (idx == len) { if (numComponents == 0) { throw log.asnOidMustHaveAtLeast2Components(); } encodeOIDComponent(bi, contents, numComponents, first); writeElement(OBJECT_IDENTIFIER_TYPE, contents); return; } } } else { t = 10L * t + (long) digit; } } else if (c == '.') { if (numComponents == 0) { first = validateFirstOIDComponent(t); } else { encodeOIDComponent(t, contents, numComponents, first); } numComponents++; t = 0L; } else { throw log.asnInvalidOidCharacter(); } if (idx == len) { if (c == '.') { throw log.asnInvalidOidCharacter(); } if (numComponents == 0) { throw log.asnOidMustHaveAtLeast2Components(); } encodeOIDComponent(t, contents, numComponents, first); writeElement(OBJECT_IDENTIFIER_TYPE, contents); return; } } }
DEREncoder implements ASN1Encoder { @Override public void encodeObjectIdentifier(String objectIdentifier) throws ASN1Exception { if (objectIdentifier == null || objectIdentifier.length() == 0) { throw log.asnOidMustHaveAtLeast2Components(); } int len = objectIdentifier.length(); int offs = 0; int idx = 0; long t = 0L; char c; int numComponents = 0; int first = -1; ByteStringBuilder contents = new ByteStringBuilder(); a: for (;;) { c = objectIdentifier.charAt(offs + idx ++); if (Character.isDigit(c)) { int digit = Character.digit(c, 10); if (t > LARGEST_UNSHIFTED_LONG) { BigInteger bi = BigInteger.valueOf(t).multiply(BigInteger.TEN).add(digits[digit]); t = 0L; for (;;) { c = objectIdentifier.charAt(offs + idx ++); if (Character.isDigit(c)) { digit = Character.digit(c, 10); bi = bi.multiply(BigInteger.TEN).add(digits[digit]); } else if (c == '.') { if (numComponents == 0) { first = validateFirstOIDComponent(bi); } else { encodeOIDComponent(bi, contents, numComponents, first); } numComponents++; continue a; } else { throw log.asnInvalidOidCharacter(); } if (idx == len) { if (numComponents == 0) { throw log.asnOidMustHaveAtLeast2Components(); } encodeOIDComponent(bi, contents, numComponents, first); writeElement(OBJECT_IDENTIFIER_TYPE, contents); return; } } } else { t = 10L * t + (long) digit; } } else if (c == '.') { if (numComponents == 0) { first = validateFirstOIDComponent(t); } else { encodeOIDComponent(t, contents, numComponents, first); } numComponents++; t = 0L; } else { throw log.asnInvalidOidCharacter(); } if (idx == len) { if (c == '.') { throw log.asnInvalidOidCharacter(); } if (numComponents == 0) { throw log.asnOidMustHaveAtLeast2Components(); } encodeOIDComponent(t, contents, numComponents, first); writeElement(OBJECT_IDENTIFIER_TYPE, contents); return; } } } }
DEREncoder implements ASN1Encoder { @Override public void encodeObjectIdentifier(String objectIdentifier) throws ASN1Exception { if (objectIdentifier == null || objectIdentifier.length() == 0) { throw log.asnOidMustHaveAtLeast2Components(); } int len = objectIdentifier.length(); int offs = 0; int idx = 0; long t = 0L; char c; int numComponents = 0; int first = -1; ByteStringBuilder contents = new ByteStringBuilder(); a: for (;;) { c = objectIdentifier.charAt(offs + idx ++); if (Character.isDigit(c)) { int digit = Character.digit(c, 10); if (t > LARGEST_UNSHIFTED_LONG) { BigInteger bi = BigInteger.valueOf(t).multiply(BigInteger.TEN).add(digits[digit]); t = 0L; for (;;) { c = objectIdentifier.charAt(offs + idx ++); if (Character.isDigit(c)) { digit = Character.digit(c, 10); bi = bi.multiply(BigInteger.TEN).add(digits[digit]); } else if (c == '.') { if (numComponents == 0) { first = validateFirstOIDComponent(bi); } else { encodeOIDComponent(bi, contents, numComponents, first); } numComponents++; continue a; } else { throw log.asnInvalidOidCharacter(); } if (idx == len) { if (numComponents == 0) { throw log.asnOidMustHaveAtLeast2Components(); } encodeOIDComponent(bi, contents, numComponents, first); writeElement(OBJECT_IDENTIFIER_TYPE, contents); return; } } } else { t = 10L * t + (long) digit; } } else if (c == '.') { if (numComponents == 0) { first = validateFirstOIDComponent(t); } else { encodeOIDComponent(t, contents, numComponents, first); } numComponents++; t = 0L; } else { throw log.asnInvalidOidCharacter(); } if (idx == len) { if (c == '.') { throw log.asnInvalidOidCharacter(); } if (numComponents == 0) { throw log.asnOidMustHaveAtLeast2Components(); } encodeOIDComponent(t, contents, numComponents, first); writeElement(OBJECT_IDENTIFIER_TYPE, contents); return; } } } DEREncoder();   DEREncoder(ByteStringBuilder target); }
DEREncoder implements ASN1Encoder { @Override public void encodeObjectIdentifier(String objectIdentifier) throws ASN1Exception { if (objectIdentifier == null || objectIdentifier.length() == 0) { throw log.asnOidMustHaveAtLeast2Components(); } int len = objectIdentifier.length(); int offs = 0; int idx = 0; long t = 0L; char c; int numComponents = 0; int first = -1; ByteStringBuilder contents = new ByteStringBuilder(); a: for (;;) { c = objectIdentifier.charAt(offs + idx ++); if (Character.isDigit(c)) { int digit = Character.digit(c, 10); if (t > LARGEST_UNSHIFTED_LONG) { BigInteger bi = BigInteger.valueOf(t).multiply(BigInteger.TEN).add(digits[digit]); t = 0L; for (;;) { c = objectIdentifier.charAt(offs + idx ++); if (Character.isDigit(c)) { digit = Character.digit(c, 10); bi = bi.multiply(BigInteger.TEN).add(digits[digit]); } else if (c == '.') { if (numComponents == 0) { first = validateFirstOIDComponent(bi); } else { encodeOIDComponent(bi, contents, numComponents, first); } numComponents++; continue a; } else { throw log.asnInvalidOidCharacter(); } if (idx == len) { if (numComponents == 0) { throw log.asnOidMustHaveAtLeast2Components(); } encodeOIDComponent(bi, contents, numComponents, first); writeElement(OBJECT_IDENTIFIER_TYPE, contents); return; } } } else { t = 10L * t + (long) digit; } } else if (c == '.') { if (numComponents == 0) { first = validateFirstOIDComponent(t); } else { encodeOIDComponent(t, contents, numComponents, first); } numComponents++; t = 0L; } else { throw log.asnInvalidOidCharacter(); } if (idx == len) { if (c == '.') { throw log.asnInvalidOidCharacter(); } if (numComponents == 0) { throw log.asnOidMustHaveAtLeast2Components(); } encodeOIDComponent(t, contents, numComponents, first); writeElement(OBJECT_IDENTIFIER_TYPE, contents); return; } } } DEREncoder();   DEREncoder(ByteStringBuilder target); @Override void startSequence(); @Override void startSet(); @Override void startSetOf(); @Override void startExplicit(int number); @Override void startExplicit(int clazz, int number); @Override void endSequence(); @Override void endExplicit(); @Override void endSet(); @Override void endSetOf(); @Override void encodeOctetString(String str); @Override void encodeOctetString(byte[] str); @Override void encodeIA5String(String str); @Override void encodeIA5String(byte[] str); @Override void encodePrintableString(final byte[] str); @Override void encodePrintableString(final String str); @Override void encodeUTF8String(final String str); @Override void encodeBMPString(final String str); @Override void encodeUniversalString(final String str); @Override void encodeBitString(byte[] str); @Override void encodeBitString(byte[] str, int numUnusedBits); @Override void encodeBitString(final EnumSet<?> enumSet); @Override void encodeBitString(final BitSet bitSet); @Override void encodeBitString(String binaryStr); @Override void encodeBitString(BigInteger integer); @Override void encodeGeneralizedTime(final ZonedDateTime time); @Override void encodeObjectIdentifier(String objectIdentifier); @Override void encodeNull(); @Override void encodeImplicit(int number); @Override void encodeImplicit(int clazz, int number); @Override void encodeBoolean(final boolean value); @Override void encodeInteger(BigInteger integer); @Override void writeEncoded(byte[] encoded); @Override void flush(); @Override byte[] getEncoded(); }
DEREncoder implements ASN1Encoder { @Override public void encodeObjectIdentifier(String objectIdentifier) throws ASN1Exception { if (objectIdentifier == null || objectIdentifier.length() == 0) { throw log.asnOidMustHaveAtLeast2Components(); } int len = objectIdentifier.length(); int offs = 0; int idx = 0; long t = 0L; char c; int numComponents = 0; int first = -1; ByteStringBuilder contents = new ByteStringBuilder(); a: for (;;) { c = objectIdentifier.charAt(offs + idx ++); if (Character.isDigit(c)) { int digit = Character.digit(c, 10); if (t > LARGEST_UNSHIFTED_LONG) { BigInteger bi = BigInteger.valueOf(t).multiply(BigInteger.TEN).add(digits[digit]); t = 0L; for (;;) { c = objectIdentifier.charAt(offs + idx ++); if (Character.isDigit(c)) { digit = Character.digit(c, 10); bi = bi.multiply(BigInteger.TEN).add(digits[digit]); } else if (c == '.') { if (numComponents == 0) { first = validateFirstOIDComponent(bi); } else { encodeOIDComponent(bi, contents, numComponents, first); } numComponents++; continue a; } else { throw log.asnInvalidOidCharacter(); } if (idx == len) { if (numComponents == 0) { throw log.asnOidMustHaveAtLeast2Components(); } encodeOIDComponent(bi, contents, numComponents, first); writeElement(OBJECT_IDENTIFIER_TYPE, contents); return; } } } else { t = 10L * t + (long) digit; } } else if (c == '.') { if (numComponents == 0) { first = validateFirstOIDComponent(t); } else { encodeOIDComponent(t, contents, numComponents, first); } numComponents++; t = 0L; } else { throw log.asnInvalidOidCharacter(); } if (idx == len) { if (c == '.') { throw log.asnInvalidOidCharacter(); } if (numComponents == 0) { throw log.asnOidMustHaveAtLeast2Components(); } encodeOIDComponent(t, contents, numComponents, first); writeElement(OBJECT_IDENTIFIER_TYPE, contents); return; } } } DEREncoder();   DEREncoder(ByteStringBuilder target); @Override void startSequence(); @Override void startSet(); @Override void startSetOf(); @Override void startExplicit(int number); @Override void startExplicit(int clazz, int number); @Override void endSequence(); @Override void endExplicit(); @Override void endSet(); @Override void endSetOf(); @Override void encodeOctetString(String str); @Override void encodeOctetString(byte[] str); @Override void encodeIA5String(String str); @Override void encodeIA5String(byte[] str); @Override void encodePrintableString(final byte[] str); @Override void encodePrintableString(final String str); @Override void encodeUTF8String(final String str); @Override void encodeBMPString(final String str); @Override void encodeUniversalString(final String str); @Override void encodeBitString(byte[] str); @Override void encodeBitString(byte[] str, int numUnusedBits); @Override void encodeBitString(final EnumSet<?> enumSet); @Override void encodeBitString(final BitSet bitSet); @Override void encodeBitString(String binaryStr); @Override void encodeBitString(BigInteger integer); @Override void encodeGeneralizedTime(final ZonedDateTime time); @Override void encodeObjectIdentifier(String objectIdentifier); @Override void encodeNull(); @Override void encodeImplicit(int number); @Override void encodeImplicit(int clazz, int number); @Override void encodeBoolean(final boolean value); @Override void encodeInteger(BigInteger integer); @Override void writeEncoded(byte[] encoded); @Override void flush(); @Override byte[] getEncoded();  }