public BerObjectIdentifier append(int value) { if (this.value == null) { return new BerObjectIdentifier(new int[] { value }); } int[] values = new int[this.value.length + 1]; for (int i = 0; i < this.value.length; ++i) { values[i] = this.value[i]; } values[values.length - 1] = value; return new BerObjectIdentifier(values); }
public BerObjectIdentifier append(int value) { if (this.value == null) { return new BerObjectIdentifier(new int[] { value }); } int[] values = new int[this.value.length + 1]; for (int i = 0; i < this.value.length; ++i) { values[i] = this.value[i]; } values[values.length - 1] = value; return new BerObjectIdentifier(values); }
public BerObjectIdentifier append(int value) { if (this.value == null) { return new BerObjectIdentifier(new int[] { value }); } int[] values = new int[this.value.length + 1]; for (int i = 0; i < this.value.length; ++i) { values[i] = this.value[i]; } values[values.length - 1] = value; return new BerObjectIdentifier(values); }
@Test public void explicitDecoding() throws IOException { ByteArrayInputStream berInputStream = new ByteArrayInputStream(expectedBytes); BerObjectIdentifier oi = new BerObjectIdentifier(); oi.decode(berInputStream, true); Assert.assertArrayEquals(objectIdentifierComponents, oi.value); ByteArrayInputStream berInputStream2 = new ByteArrayInputStream(expectedBytes2); BerObjectIdentifier oi2 = new BerObjectIdentifier(); oi2.decode(berInputStream2, true); } }
public int decode(InputStream is, boolean withTag) throws IOException { int codeLength = 0; int subCodeLength = 0; BerTag berTag = new BerTag(); if (withTag) { codeLength += tag.decodeAndCheck(is); } BerLength length = new BerLength(); codeLength += length.decode(is); int totalLength = length.val; codeLength += totalLength; subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { abstract_ = new BerObjectIdentifier(); subCodeLength += abstract_.decode(is, false); subCodeLength += berTag.decode(is); } else { throw new IOException("Tag does not match the mandatory sequence element tag."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { transfer = new BerObjectIdentifier(); subCodeLength += transfer.decode(is, false); if (subCodeLength == totalLength) { return codeLength; } } throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); }
public int decode(InputStream is, boolean withTag) throws IOException { int codeLength = 0; int subCodeLength = 0; BerTag berTag = new BerTag(); if (withTag) { codeLength += tag.decodeAndCheck(is); } BerLength length = new BerLength(); codeLength += length.decode(is); int totalLength = length.val; codeLength += totalLength; subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { abstract_ = new BerObjectIdentifier(); subCodeLength += abstract_.decode(is, false); subCodeLength += berTag.decode(is); } else { throw new IOException("Tag does not match the mandatory sequence element tag."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { transfer = new BerObjectIdentifier(); subCodeLength += transfer.decode(is, false); if (subCodeLength == totalLength) { return codeLength; } } throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); }
public int decode(InputStream is, boolean withTag) throws IOException { int codeLength = 0; int subCodeLength = 0; BerTag berTag = new BerTag(); if (withTag) { codeLength += tag.decodeAndCheck(is); } BerLength length = new BerLength(); codeLength += length.decode(is); int totalLength = length.val; codeLength += totalLength; subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { abstract_ = new BerObjectIdentifier(); subCodeLength += abstract_.decode(is, false); subCodeLength += berTag.decode(is); } else { throw new IOException("Tag does not match the mandatory sequence element tag."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { transfer = new BerObjectIdentifier(); subCodeLength += transfer.decode(is, false); if (subCodeLength == totalLength) { return codeLength; } } throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); }
BerObjectIdentifier element = new BerObjectIdentifier(); subCodeLength += element.decode(is, false); seqOf.add(element); BerObjectIdentifier element = new BerObjectIdentifier(); subCodeLength += element.decode(is, true); seqOf.add(element);
public int decode(InputStream is, boolean withTag) throws IOException { int codeLength = 0; int subCodeLength = 0; BerTag berTag = new BerTag(); if (withTag) { codeLength += tag.decodeAndCheck(is); } BerLength length = new BerLength(); codeLength += length.decode(is); int totalLength = length.val; codeLength += totalLength; subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { presentationContextId = new BerInteger(); subCodeLength += presentationContextId.decode(is, false); subCodeLength += berTag.decode(is); } else { throw new IOException("Tag does not match the mandatory sequence element tag."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { transferSyntax = new BerObjectIdentifier(); subCodeLength += transferSyntax.decode(is, false); if (subCodeLength == totalLength) { return codeLength; } } throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); }
public int decode(InputStream is, boolean withTag) throws IOException { int codeLength = 0; int subCodeLength = 0; BerTag berTag = new BerTag(); if (withTag) { codeLength += tag.decodeAndCheck(is); } BerLength length = new BerLength(); codeLength += length.decode(is); int totalLength = length.val; codeLength += totalLength; subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { presentationContextId = new BerInteger(); subCodeLength += presentationContextId.decode(is, false); subCodeLength += berTag.decode(is); } else { throw new IOException("Tag does not match the mandatory sequence element tag."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { transferSyntax = new BerObjectIdentifier(); subCodeLength += transferSyntax.decode(is, false); if (subCodeLength == totalLength) { return codeLength; } } throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); }
public int decode(InputStream is, boolean withTag) throws IOException { int codeLength = 0; int subCodeLength = 0; BerTag berTag = new BerTag(); if (withTag) { codeLength += tag.decodeAndCheck(is); } BerLength length = new BerLength(); codeLength += length.decode(is); int totalLength = length.val; codeLength += totalLength; subCodeLength += berTag.decode(is); if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 0)) { presentationContextId = new BerInteger(); subCodeLength += presentationContextId.decode(is, false); subCodeLength += berTag.decode(is); } else { throw new IOException("Tag does not match the mandatory sequence element tag."); } if (berTag.equals(BerTag.CONTEXT_CLASS, BerTag.PRIMITIVE, 1)) { transferSyntax = new BerObjectIdentifier(); subCodeLength += transferSyntax.decode(is, false); if (subCodeLength == totalLength) { return codeLength; } } throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); }
syntax = new BerObjectIdentifier(); codeLength += syntax.decode(is, false); return codeLength; transferSyntax = new BerObjectIdentifier(); codeLength += transferSyntax.decode(is, false); return codeLength;
@Test public void explicitEncoding() throws IOException { ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50); BerObjectIdentifier oi = new BerObjectIdentifier(objectIdentifierComponents); int length = oi.encode(berBAOStream, true); Assert.assertEquals(7, length); Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
public int decode(InputStream is, boolean withTag) throws IOException { int codeLength = 0; int subCodeLength = 0; BerTag berTag = new BerTag(); if (withTag) { codeLength += tag.decodeAndCheck(is); } BerLength length = new BerLength(); codeLength += length.decode(is); int totalLength = length.val; codeLength += totalLength; subCodeLength += berTag.decode(is); if (berTag.equals(BerObjectIdentifier.tag)) { directReference = new BerObjectIdentifier(); subCodeLength += directReference.decode(is, false); subCodeLength += berTag.decode(is); } if (berTag.equals(BerInteger.tag)) { indirectReference = new BerInteger(); subCodeLength += indirectReference.decode(is, false); subCodeLength += berTag.decode(is); } encoding = new Encoding(); subCodeLength += encoding.decode(is, berTag); if (subCodeLength == totalLength) { return codeLength; } throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); }
public int decode(InputStream is, boolean withTag) throws IOException { int codeLength = 0; int subCodeLength = 0; BerTag berTag = new BerTag(); if (withTag) { codeLength += tag.decodeAndCheck(is); } BerLength length = new BerLength(); codeLength += length.decode(is); int totalLength = length.val; codeLength += totalLength; subCodeLength += berTag.decode(is); if (berTag.equals(BerObjectIdentifier.tag)) { directReference = new BerObjectIdentifier(); subCodeLength += directReference.decode(is, false); subCodeLength += berTag.decode(is); } if (berTag.equals(BerInteger.tag)) { indirectReference = new BerInteger(); subCodeLength += indirectReference.decode(is, false); subCodeLength += berTag.decode(is); } encoding = new Encoding(); subCodeLength += encoding.decode(is, berTag); if (subCodeLength == totalLength) { return codeLength; } throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); }
public int decode(InputStream is, boolean withTag) throws IOException { int codeLength = 0; int subCodeLength = 0; BerTag berTag = new BerTag(); if (withTag) { codeLength += tag.decodeAndCheck(is); } BerLength length = new BerLength(); codeLength += length.decode(is); int totalLength = length.val; codeLength += totalLength; subCodeLength += berTag.decode(is); if (berTag.equals(BerObjectIdentifier.tag)) { directReference = new BerObjectIdentifier(); subCodeLength += directReference.decode(is, false); subCodeLength += berTag.decode(is); } if (berTag.equals(BerInteger.tag)) { indirectReference = new BerInteger(); subCodeLength += indirectReference.decode(is, false); subCodeLength += berTag.decode(is); } encoding = new Encoding(); subCodeLength += encoding.decode(is, berTag); if (subCodeLength == totalLength) { return codeLength; } throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); }
public int decode(InputStream is, boolean withTag) throws IOException { int codeLength = 0; int subCodeLength = 0; BerTag berTag = new BerTag(); if (withTag) { codeLength += tag.decodeAndCheck(is); } BerLength length = new BerLength(); codeLength += length.decode(is); int totalLength = length.val; codeLength += totalLength; subCodeLength += berTag.decode(is); if (berTag.equals(BerObjectIdentifier.tag)) { directReference = new BerObjectIdentifier(); subCodeLength += directReference.decode(is, false); subCodeLength += berTag.decode(is); } if (berTag.equals(BerInteger.tag)) { indirectReference = new BerInteger(); subCodeLength += indirectReference.decode(is, false); subCodeLength += berTag.decode(is); } encoding = new Encoding(); subCodeLength += encoding.decode(is, berTag); if (subCodeLength == totalLength) { return codeLength; } throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); }
public int decode(InputStream is, boolean withTag) throws IOException { int codeLength = 0; int subCodeLength = 0; BerTag berTag = new BerTag(); if (withTag) { codeLength += tag.decodeAndCheck(is); } BerLength length = new BerLength(); codeLength += length.decode(is); int totalLength = length.val; codeLength += totalLength; subCodeLength += berTag.decode(is); if (berTag.equals(BerObjectIdentifier.tag)) { directReference = new BerObjectIdentifier(); subCodeLength += directReference.decode(is, false); subCodeLength += berTag.decode(is); } if (berTag.equals(BerInteger.tag)) { indirectReference = new BerInteger(); subCodeLength += indirectReference.decode(is, false); subCodeLength += berTag.decode(is); } encoding = new Encoding(); subCodeLength += encoding.decode(is, berTag); if (subCodeLength == totalLength) { return codeLength; } throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); }
public int decode(InputStream is, boolean withTag) throws IOException { int codeLength = 0; int subCodeLength = 0; BerTag berTag = new BerTag(); if (withTag) { codeLength += tag.decodeAndCheck(is); } BerLength length = new BerLength(); codeLength += length.decode(is); int totalLength = length.val; codeLength += totalLength; subCodeLength += berTag.decode(is); if (berTag.equals(BerObjectIdentifier.tag)) { directReference = new BerObjectIdentifier(); subCodeLength += directReference.decode(is, false); subCodeLength += berTag.decode(is); } if (berTag.equals(BerInteger.tag)) { indirectReference = new BerInteger(); subCodeLength += indirectReference.decode(is, false); subCodeLength += berTag.decode(is); } encoding = new Encoding(); subCodeLength += encoding.decode(is, berTag); if (subCodeLength == totalLength) { return codeLength; } throw new IOException("Unexpected end of sequence, length tag: " + totalLength + ", actual sequence length: " + subCodeLength); }
@Test public void header() throws Exception { ProfileElement headerProfileElement = new ProfileElement(); ServicesList servicesList = new ServicesList(); ProfileHeader.EUICCMandatoryGFSTEList GFSTEList = new ProfileHeader.EUICCMandatoryGFSTEList(); GFSTEList.seqOf = Arrays.asList(new BerObjectIdentifier(new int[] { 2, 23, 143, 1, 2, 1 }), new BerObjectIdentifier(new int[] { 2, 23, 143, 1, 2, 4 })); servicesList.usim = new BerNull(); servicesList.milenage = new BerNull(); servicesList.javacard = new BerNull(); headerProfileElement.header = new ProfileHeader(new UInt8(2), new UInt8(0), new BerUTF8String("SIMalliance Sample Profile"), new BerOctetString(DatatypeConverter.parseHexBinary("89019990001234567893")), null, servicesList, GFSTEList, null); ReverseByteArrayOutputStream reverseByteArrayOutputStream = new ReverseByteArrayOutputStream(2048, true); headerProfileElement.encode(reverseByteArrayOutputStream); byte[] code = reverseByteArrayOutputStream.getArray(); ProfileElement rereadProfileElement = new ProfileElement(); rereadProfileElement.decode(new ByteArrayInputStream(code), null); ReverseByteArrayOutputStream reverseOutputStream2 = new ReverseByteArrayOutputStream(2048, true); rereadProfileElement.encode(reverseOutputStream2); byte[] code2 = reverseOutputStream2.getArray(); Assert.assertArrayEquals(code, code2); String expected = "A0 48 80 01 02 81 01 00 82 1A 53494D616C6C69616E63652053616D706C652050726F66696C65 83 0A 89019990001234567893 A5 06 81 00 84 00 8B 00 A6 10 06 06 67810F010201 06 06 67810F010204" .replaceAll("\\s", ""); Assert.assertEquals(expected, DatatypeConverter.printHexBinary(code)); }