target
stringlengths
20
113k
src_fm
stringlengths
11
86.3k
src_fm_fc
stringlengths
21
86.4k
src_fm_fc_co
stringlengths
30
86.4k
src_fm_fc_ms
stringlengths
42
86.8k
src_fm_fc_ms_ff
stringlengths
43
86.8k
@Test( expected = AssertionError.class ) public void testEncode_fail_value() throws Exception { Scope scope = CoreModule.getInstance().createScope(); Type type = UniversalType.UTC_TIME.ref().resolve( scope ); Value value = BooleanValue.TRUE; try( AbstractBerWriter writer = mock( AbstractBerWriter.class ) ) { new UTCTimeBerEncoder().encode( new WriterContext( writer, scope, type, value, false ) ); fail( "Must fail" ); } }
@Override public void encode( @NotNull WriterContext context ) throws IOException, Asn1Exception { assert context.getType().getFamily() == Family.UTC_TIME; assert context.getValue().getKind() == Kind.TIME; String content = TimeUtils.formatInstant( context.getValue().toDateValue().asInstant(), TimeUtils.UTC_TIME_FORMAT, context.getRules() != BerRules.DER ); byte[] bytes = content.getBytes( TimeUtils.CHARSET ); context.writeHeader( TAG, bytes.length ); context.write( bytes ); }
UTCTimeBerEncoder implements BerEncoder { @Override public void encode( @NotNull WriterContext context ) throws IOException, Asn1Exception { assert context.getType().getFamily() == Family.UTC_TIME; assert context.getValue().getKind() == Kind.TIME; String content = TimeUtils.formatInstant( context.getValue().toDateValue().asInstant(), TimeUtils.UTC_TIME_FORMAT, context.getRules() != BerRules.DER ); byte[] bytes = content.getBytes( TimeUtils.CHARSET ); context.writeHeader( TAG, bytes.length ); context.write( bytes ); } }
UTCTimeBerEncoder implements BerEncoder { @Override public void encode( @NotNull WriterContext context ) throws IOException, Asn1Exception { assert context.getType().getFamily() == Family.UTC_TIME; assert context.getValue().getKind() == Kind.TIME; String content = TimeUtils.formatInstant( context.getValue().toDateValue().asInstant(), TimeUtils.UTC_TIME_FORMAT, context.getRules() != BerRules.DER ); byte[] bytes = content.getBytes( TimeUtils.CHARSET ); context.writeHeader( TAG, bytes.length ); context.write( bytes ); } }
UTCTimeBerEncoder implements BerEncoder { @Override public void encode( @NotNull WriterContext context ) throws IOException, Asn1Exception { assert context.getType().getFamily() == Family.UTC_TIME; assert context.getValue().getKind() == Kind.TIME; String content = TimeUtils.formatInstant( context.getValue().toDateValue().asInstant(), TimeUtils.UTC_TIME_FORMAT, context.getRules() != BerRules.DER ); byte[] bytes = content.getBytes( TimeUtils.CHARSET ); context.writeHeader( TAG, bytes.length ); context.write( bytes ); } @Override void encode( @NotNull WriterContext context ); }
UTCTimeBerEncoder implements BerEncoder { @Override public void encode( @NotNull WriterContext context ) throws IOException, Asn1Exception { assert context.getType().getFamily() == Family.UTC_TIME; assert context.getValue().getKind() == Kind.TIME; String content = TimeUtils.formatInstant( context.getValue().toDateValue().asInstant(), TimeUtils.UTC_TIME_FORMAT, context.getRules() != BerRules.DER ); byte[] bytes = content.getBytes( TimeUtils.CHARSET ); context.writeHeader( TAG, bytes.length ); context.write( bytes ); } @Override void encode( @NotNull WriterContext context ); }
@Test public void testEncode_0() throws Exception { Scope scope = CoreModule.getInstance().createScope(); Enumerated type = new EnumeratedType(); type.addItem( ItemKind.PRIMARY, "a", new IntegerValueInt( 0 ) ); type.validate( scope ); Value value = type.optimize( scope, new IntegerValueInt( 0 ) ); try( AbstractBerWriter writer = mock( AbstractBerWriter.class ) ) { new EnumeratedBerEncoder().encode( new WriterContext( writer, scope, type, value, true ) ); verify( writer ).writeHeader( TAG, 1 ); verify( writer ).write( 0 ); verifyNoMoreInteractions( writer ); } }
@Override public void encode( @NotNull WriterContext context ) throws IOException { assert context.getType().getFamily() == Family.ENUMERATED; assert context.getValue().getKind() == Kind.NAME && context.getValue().toNamedValue().getReferenceKind() == Kind.INTEGER; IntegerBerEncoder.writeLong( context.getWriter(), context.getValue().toIntegerValue().asLong(), TAG, context.isWriteHeader() ); }
EnumeratedBerEncoder implements BerEncoder { @Override public void encode( @NotNull WriterContext context ) throws IOException { assert context.getType().getFamily() == Family.ENUMERATED; assert context.getValue().getKind() == Kind.NAME && context.getValue().toNamedValue().getReferenceKind() == Kind.INTEGER; IntegerBerEncoder.writeLong( context.getWriter(), context.getValue().toIntegerValue().asLong(), TAG, context.isWriteHeader() ); } }
EnumeratedBerEncoder implements BerEncoder { @Override public void encode( @NotNull WriterContext context ) throws IOException { assert context.getType().getFamily() == Family.ENUMERATED; assert context.getValue().getKind() == Kind.NAME && context.getValue().toNamedValue().getReferenceKind() == Kind.INTEGER; IntegerBerEncoder.writeLong( context.getWriter(), context.getValue().toIntegerValue().asLong(), TAG, context.isWriteHeader() ); } }
EnumeratedBerEncoder implements BerEncoder { @Override public void encode( @NotNull WriterContext context ) throws IOException { assert context.getType().getFamily() == Family.ENUMERATED; assert context.getValue().getKind() == Kind.NAME && context.getValue().toNamedValue().getReferenceKind() == Kind.INTEGER; IntegerBerEncoder.writeLong( context.getWriter(), context.getValue().toIntegerValue().asLong(), TAG, context.isWriteHeader() ); } @Override void encode( @NotNull WriterContext context ); }
EnumeratedBerEncoder implements BerEncoder { @Override public void encode( @NotNull WriterContext context ) throws IOException { assert context.getType().getFamily() == Family.ENUMERATED; assert context.getValue().getKind() == Kind.NAME && context.getValue().toNamedValue().getReferenceKind() == Kind.INTEGER; IntegerBerEncoder.writeLong( context.getWriter(), context.getValue().toIntegerValue().asLong(), TAG, context.isWriteHeader() ); } @Override void encode( @NotNull WriterContext context ); }
@Test( expected = AssertionError.class ) public void testEncode_fail_type() throws Exception { Scope scope = CoreModule.getInstance().createScope(); Type type = UniversalType.INTEGER.ref().resolve( scope ); Value value = new NamedValueImpl( "abc", new IntegerValueInt( 0 ) ); try( AbstractBerWriter writer = mock( AbstractBerWriter.class ) ) { new EnumeratedBerEncoder().encode( new WriterContext( writer, scope, type, value, false ) ); fail( "Must fail" ); } }
@Override public void encode( @NotNull WriterContext context ) throws IOException { assert context.getType().getFamily() == Family.ENUMERATED; assert context.getValue().getKind() == Kind.NAME && context.getValue().toNamedValue().getReferenceKind() == Kind.INTEGER; IntegerBerEncoder.writeLong( context.getWriter(), context.getValue().toIntegerValue().asLong(), TAG, context.isWriteHeader() ); }
EnumeratedBerEncoder implements BerEncoder { @Override public void encode( @NotNull WriterContext context ) throws IOException { assert context.getType().getFamily() == Family.ENUMERATED; assert context.getValue().getKind() == Kind.NAME && context.getValue().toNamedValue().getReferenceKind() == Kind.INTEGER; IntegerBerEncoder.writeLong( context.getWriter(), context.getValue().toIntegerValue().asLong(), TAG, context.isWriteHeader() ); } }
EnumeratedBerEncoder implements BerEncoder { @Override public void encode( @NotNull WriterContext context ) throws IOException { assert context.getType().getFamily() == Family.ENUMERATED; assert context.getValue().getKind() == Kind.NAME && context.getValue().toNamedValue().getReferenceKind() == Kind.INTEGER; IntegerBerEncoder.writeLong( context.getWriter(), context.getValue().toIntegerValue().asLong(), TAG, context.isWriteHeader() ); } }
EnumeratedBerEncoder implements BerEncoder { @Override public void encode( @NotNull WriterContext context ) throws IOException { assert context.getType().getFamily() == Family.ENUMERATED; assert context.getValue().getKind() == Kind.NAME && context.getValue().toNamedValue().getReferenceKind() == Kind.INTEGER; IntegerBerEncoder.writeLong( context.getWriter(), context.getValue().toIntegerValue().asLong(), TAG, context.isWriteHeader() ); } @Override void encode( @NotNull WriterContext context ); }
EnumeratedBerEncoder implements BerEncoder { @Override public void encode( @NotNull WriterContext context ) throws IOException { assert context.getType().getFamily() == Family.ENUMERATED; assert context.getValue().getKind() == Kind.NAME && context.getValue().toNamedValue().getReferenceKind() == Kind.INTEGER; IntegerBerEncoder.writeLong( context.getWriter(), context.getValue().toIntegerValue().asLong(), TAG, context.isWriteHeader() ); } @Override void encode( @NotNull WriterContext context ); }
@Test( expected = AssertionError.class ) public void testDecode_fail_type() throws Exception { Scope scope = CoreModule.getInstance().createScope(); Type type = UniversalType.INTEGER.ref().resolve( scope ); try( AbstractBerReader reader = mock( DefaultBerReader.class ) ) { Tag tag = ( (TagEncoding)type.getEncoding( EncodingInstructions.TAG ) ).toTag( false ); new StringBerDecoder().decode( new ReaderContext( reader, scope, type, tag, -1, false ) ); fail( "Must fail" ); } }
@Override public Value decode( @NotNull ReaderContext context ) throws IOException, Asn1Exception { assert context.getType().getFamily() == Family.RESTRICTED_STRING; Type type = context.getType(); while( !( type instanceof StringType ) ) { assert type != null; type = type.getSibling(); } byte[] content = BerDecoderUtils.readString( context.getReader(), context.getLength() ); return context.getValueFactory().cString( new String( content, ( (StringType)type ).getCharset() ) ); }
StringBerDecoder implements BerDecoder { @Override public Value decode( @NotNull ReaderContext context ) throws IOException, Asn1Exception { assert context.getType().getFamily() == Family.RESTRICTED_STRING; Type type = context.getType(); while( !( type instanceof StringType ) ) { assert type != null; type = type.getSibling(); } byte[] content = BerDecoderUtils.readString( context.getReader(), context.getLength() ); return context.getValueFactory().cString( new String( content, ( (StringType)type ).getCharset() ) ); } }
StringBerDecoder implements BerDecoder { @Override public Value decode( @NotNull ReaderContext context ) throws IOException, Asn1Exception { assert context.getType().getFamily() == Family.RESTRICTED_STRING; Type type = context.getType(); while( !( type instanceof StringType ) ) { assert type != null; type = type.getSibling(); } byte[] content = BerDecoderUtils.readString( context.getReader(), context.getLength() ); return context.getValueFactory().cString( new String( content, ( (StringType)type ).getCharset() ) ); } }
StringBerDecoder implements BerDecoder { @Override public Value decode( @NotNull ReaderContext context ) throws IOException, Asn1Exception { assert context.getType().getFamily() == Family.RESTRICTED_STRING; Type type = context.getType(); while( !( type instanceof StringType ) ) { assert type != null; type = type.getSibling(); } byte[] content = BerDecoderUtils.readString( context.getReader(), context.getLength() ); return context.getValueFactory().cString( new String( content, ( (StringType)type ).getCharset() ) ); } @Override Value decode( @NotNull ReaderContext context ); }
StringBerDecoder implements BerDecoder { @Override public Value decode( @NotNull ReaderContext context ) throws IOException, Asn1Exception { assert context.getType().getFamily() == Family.RESTRICTED_STRING; Type type = context.getType(); while( !( type instanceof StringType ) ) { assert type != null; type = type.getSibling(); } byte[] content = BerDecoderUtils.readString( context.getReader(), context.getLength() ); return context.getValueFactory().cString( new String( content, ( (StringType)type ).getCharset() ) ); } @Override Value decode( @NotNull ReaderContext context ); }
@Test( expected = AssertionError.class ) public void testEncode_fail_value() throws Exception { Scope scope = CoreModule.getInstance().createScope(); Enumerated type = new EnumeratedType(); type.addItem( ItemKind.PRIMARY, "a", new IntegerValueInt( 0 ) ); type.validate( scope ); Value value = BooleanValue.TRUE; try( AbstractBerWriter writer = mock( AbstractBerWriter.class ) ) { new EnumeratedBerEncoder().encode( new WriterContext( writer, scope, type, value, false ) ); fail( "Must fail" ); } }
@Override public void encode( @NotNull WriterContext context ) throws IOException { assert context.getType().getFamily() == Family.ENUMERATED; assert context.getValue().getKind() == Kind.NAME && context.getValue().toNamedValue().getReferenceKind() == Kind.INTEGER; IntegerBerEncoder.writeLong( context.getWriter(), context.getValue().toIntegerValue().asLong(), TAG, context.isWriteHeader() ); }
EnumeratedBerEncoder implements BerEncoder { @Override public void encode( @NotNull WriterContext context ) throws IOException { assert context.getType().getFamily() == Family.ENUMERATED; assert context.getValue().getKind() == Kind.NAME && context.getValue().toNamedValue().getReferenceKind() == Kind.INTEGER; IntegerBerEncoder.writeLong( context.getWriter(), context.getValue().toIntegerValue().asLong(), TAG, context.isWriteHeader() ); } }
EnumeratedBerEncoder implements BerEncoder { @Override public void encode( @NotNull WriterContext context ) throws IOException { assert context.getType().getFamily() == Family.ENUMERATED; assert context.getValue().getKind() == Kind.NAME && context.getValue().toNamedValue().getReferenceKind() == Kind.INTEGER; IntegerBerEncoder.writeLong( context.getWriter(), context.getValue().toIntegerValue().asLong(), TAG, context.isWriteHeader() ); } }
EnumeratedBerEncoder implements BerEncoder { @Override public void encode( @NotNull WriterContext context ) throws IOException { assert context.getType().getFamily() == Family.ENUMERATED; assert context.getValue().getKind() == Kind.NAME && context.getValue().toNamedValue().getReferenceKind() == Kind.INTEGER; IntegerBerEncoder.writeLong( context.getWriter(), context.getValue().toIntegerValue().asLong(), TAG, context.isWriteHeader() ); } @Override void encode( @NotNull WriterContext context ); }
EnumeratedBerEncoder implements BerEncoder { @Override public void encode( @NotNull WriterContext context ) throws IOException { assert context.getType().getFamily() == Family.ENUMERATED; assert context.getValue().getKind() == Kind.NAME && context.getValue().toNamedValue().getReferenceKind() == Kind.INTEGER; IntegerBerEncoder.writeLong( context.getWriter(), context.getValue().toIntegerValue().asLong(), TAG, context.isWriteHeader() ); } @Override void encode( @NotNull WriterContext context ); }
@Test( expected = UnsupportedOperationException.class ) public void testGetTextFail() { new GroupSyntaxObject().getText(); Assert.fail( "Exception was not thrown" ); }
@Override public String getText() { throw new UnsupportedOperationException(); }
GroupSyntaxObject implements SyntaxObject { @Override public String getText() { throw new UnsupportedOperationException(); } }
GroupSyntaxObject implements SyntaxObject { @Override public String getText() { throw new UnsupportedOperationException(); } }
GroupSyntaxObject implements SyntaxObject { @Override public String getText() { throw new UnsupportedOperationException(); } @Override Kind getKind(); @Override String getText(); void addObject( SyntaxObject object ); List<SyntaxObject> getObjects(); }
GroupSyntaxObject implements SyntaxObject { @Override public String getText() { throw new UnsupportedOperationException(); } @Override Kind getKind(); @Override String getText(); void addObject( SyntaxObject object ); List<SyntaxObject> getObjects(); }
@Test public void testAddObject() { GroupSyntaxObject group = new GroupSyntaxObject(); Assert.assertEquals( "Kind is not GROUP", Kind.GROUP, group.getKind() ); Assert.assertTrue( "Collection is not empty", group.getObjects().isEmpty() ); group.addObject( new SimpleSyntaxObject( Kind.KEYWORD, "VALUE" ) ); Assert.assertEquals( "Collection is not empty", 1, group.getObjects().size() ); }
public void addObject( SyntaxObject object ) { objects.add( object ); }
GroupSyntaxObject implements SyntaxObject { public void addObject( SyntaxObject object ) { objects.add( object ); } }
GroupSyntaxObject implements SyntaxObject { public void addObject( SyntaxObject object ) { objects.add( object ); } }
GroupSyntaxObject implements SyntaxObject { public void addObject( SyntaxObject object ) { objects.add( object ); } @Override Kind getKind(); @Override String getText(); void addObject( SyntaxObject object ); List<SyntaxObject> getObjects(); }
GroupSyntaxObject implements SyntaxObject { public void addObject( SyntaxObject object ) { objects.add( object ); } @Override Kind getKind(); @Override String getText(); void addObject( SyntaxObject object ); List<SyntaxObject> getObjects(); }
@Test( expected = ResolutionException.class ) public void testParserFail() throws Exception { ModuleImpl module = ModuleImpl.newDummy( new ModuleSet() ); AbstractSyntaxObjectRef ref = new AbstractSyntaxObjectRef( "{ ID &id }" ); ClassType classType = new ClassTypeImpl(); Scope scope = classType.getScope( module.createScope() ); AbstractSyntaxParser parser = PowerMockito.mock( AbstractSyntaxParser.class ); PowerMockito.whenNew( AbstractSyntaxParser.class ).withAnyArguments().thenReturn( parser ); when( parser.parse( anyString() ) ).thenThrow( new IllegalStateException() ); ref.resolve( scope ); }
@Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); @Override Value resolve( Scope scope ); }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); @Override Value resolve( Scope scope ); }
@Test public void testParser() throws Exception { ModuleImpl module = ModuleImpl.newDummy( new ModuleSet() ); ClassTypeImpl classType = new ClassTypeImpl(); classType.setSyntaxList( Arrays.asList( "&Type", "IDENTIFIED", "BY", "&id", "[", "CONSTRAINED", "BY", "&TypeConstraint", "]" ) ); classType.add( new ValueFieldType( "&id", UniversalType.OBJECT_IDENTIFIER.ref(), true, false ) ); classType.add( new TypeFieldType( "&Type", false, null ) ); classType.add( new TypeFieldType( "&TypeConstraint", false, null ) ); classType.validate( module.createScope() ); Ref<Value> ref = new AbstractSyntaxObjectRef( "{Super-Type IDENTIFIED BY { rootOid 3 } CONSTRAINED BY TYPE-Constraint}" ); Value value = ref.resolve( classType.getScope( module.createScope() ) ); Assert.assertNotNull( "No result", value ); ref = new AbstractSyntaxObjectRef( "{OBJECT IDENTIFIER IDENTIFIED BY { rootOid 3 } }" ); value = ref.resolve( classType.getScope( module.createScope() ) ); Assert.assertNotNull( "No result", value ); }
@Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); @Override Value resolve( Scope scope ); }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); @Override Value resolve( Scope scope ); }
@Test( expected = ResolutionException.class ) public void testNoClassType() throws Exception { AbstractSyntaxObjectRef ref = new AbstractSyntaxObjectRef( "{ ID &id }" ); ModuleImpl module = ModuleImpl.newDummy( new ModuleSet() ); DefinedTypeImpl myInt = new DefinedTypeImpl( module, "MyInt", UniversalType.INTEGER.ref() ); ref.resolve( myInt.createScope() ); }
@Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); @Override Value resolve( Scope scope ); }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); @Override Value resolve( Scope scope ); }
@Test( expected = ResolutionException.class ) public void testParserValueFail() throws Exception { ModuleImpl module = ModuleImpl.newDummy( new ModuleSet() ); ClassTypeImpl classType = new ClassTypeImpl(); classType.setSyntaxList( Arrays.asList( "&Type", "IDENTIFIED", "BY", "&id", "[", "CONSTRAINED", "BY", "&TypeConstraint", "]" ) ); classType.add( new ValueFieldType( "&id", UniversalType.OBJECT_IDENTIFIER.ref(), true, false ) ); classType.add( new TypeFieldType( "&Type", false, null ) ); classType.add( new TypeFieldType( "&TypeConstraint", false, null ) ); classType.validate( module.createScope() ); Ref<Value> ref = new AbstractSyntaxObjectRef( "{BIT STRING IDENTIFIED BY NAME { rootOid 3 } CONSTRAINED BY TYPE-Constraint}" ); Value value = ref.resolve( classType.getScope( module.createScope() ) ); Assert.assertNotNull( "No result", value ); }
@Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); @Override Value resolve( Scope scope ); }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); @Override Value resolve( Scope scope ); }
@Test public void testParserValueSequence() throws Exception { ModuleImpl module = ModuleImpl.newDummy( new ModuleSet() ); ClassTypeImpl classType = new ClassTypeImpl(); classType.setSyntaxList( Arrays.asList( "&Type", "IDENTIFIED", "BY", "&id", "[", "CONSTRAINED", "BY", "&TypeConstraint", "]" ) ); classType.add( new ValueFieldType( "&id", new SequenceType( true ), true, false ) ); classType.add( new TypeFieldType( "&Type", false, null ) ); classType.add( new TypeFieldType( "&TypeConstraint", false, null ) ); classType.validate( module.createScope() ); Ref<Value> ref = new AbstractSyntaxObjectRef( "{INTEGER IDENTIFIED BY { rootOid 3, a 2 } CONSTRAINED BY TYPE-Constraint}" ); Value value = ref.resolve( classType.getScope( module.createScope() ) ); Assert.assertNotNull( "No result", value ); ref = new AbstractSyntaxObjectRef( "{CHARACTER STRING IDENTIFIED BY { rootOid 3, a 2 } CONSTRAINED BY TYPE-Constraint}" ); value = ref.resolve( classType.getScope( module.createScope() ) ); Assert.assertNotNull( "No result", value ); ref = new AbstractSyntaxObjectRef( "{OCTET STRING IDENTIFIED BY { rootOid 3, a 2 } CONSTRAINED BY TYPE-Constraint}" ); value = ref.resolve( classType.getScope( module.createScope() ) ); Assert.assertNotNull( "No result", value ); ref = new AbstractSyntaxObjectRef( "{EMBEDDED PDV IDENTIFIED BY { rootOid 3, a 2 } CONSTRAINED BY TYPE-Constraint}" ); value = ref.resolve( classType.getScope( module.createScope() ) ); Assert.assertNotNull( "No result", value ); ref = new AbstractSyntaxObjectRef( "{EMBEDDED PDV IDENTIFIED BY 1 CONSTRAINED BY TYPE-Constraint}" ); value = ref.resolve( classType.getScope( module.createScope() ) ); Assert.assertNotNull( "No result", value ); ref = new AbstractSyntaxObjectRef( "{EMBEDDED PDV IDENTIFIED BY 1.0 CONSTRAINED BY TYPE-Constraint}" ); value = ref.resolve( classType.getScope( module.createScope() ) ); Assert.assertNotNull( "No result", value ); ref = new AbstractSyntaxObjectRef( "{EMBEDDED PDV IDENTIFIED BY 'AF'H CONSTRAINED BY TYPE-Constraint}" ); value = ref.resolve( classType.getScope( module.createScope() ) ); Assert.assertNotNull( "No result", value ); ref = new AbstractSyntaxObjectRef( "{EMBEDDED PDV IDENTIFIED BY '0101'B CONSTRAINED BY TYPE-Constraint}" ); value = ref.resolve( classType.getScope( module.createScope() ) ); Assert.assertNotNull( "No result", value ); ref = new AbstractSyntaxObjectRef( "{EMBEDDED PDV IDENTIFIED BY 'Word' CONSTRAINED BY TYPE-Constraint}" ); value = ref.resolve( classType.getScope( module.createScope() ) ); Assert.assertNotNull( "No result", value ); }
@Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); @Override Value resolve( Scope scope ); }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); @Override Value resolve( Scope scope ); }
@Test( expected = ResolutionException.class ) public void testParserFailTypeExpected() throws Exception { ModuleImpl module = ModuleImpl.newDummy( new ModuleSet() ); ClassTypeImpl classType = new ClassTypeImpl(); classType.setSyntaxList( Arrays.asList( "&Type", "IDENTIFIED", "BY", "&id", "[", "CONSTRAINED", "BY", "&TypeConstraint", "]" ) ); classType.add( new ValueFieldType( "&id", UniversalType.OBJECT_IDENTIFIER.ref(), true, false ) ); classType.add( new TypeFieldType( "&Type", false, null ) ); classType.add( new TypeFieldType( "&TypeConstraint", false, null ) ); classType.validate( module.createScope() ); Ref<Value> ref = new AbstractSyntaxObjectRef( "{1 IDENTIFIED BY { rootOid 3 } CONSTRAINED BY TYPE-Constraint}" ); Value value = ref.resolve( classType.getScope( module.createScope() ) ); Assert.assertNotNull( "No result", value ); }
@Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); @Override Value resolve( Scope scope ); }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); @Override Value resolve( Scope scope ); }
@Test public void testParserExternalRef() throws Exception { ModuleImpl module = ModuleImpl.newDummy( new ModuleSet() ); ClassTypeImpl classType = new ClassTypeImpl(); classType.setSyntaxList( Arrays.asList( "&Type", "IDENTIFIED", "BY", "&id", "[", "CONSTRAINED", "BY", "&TypeConstraint", "]" ) ); classType.add( new ValueFieldType( "&id", UniversalType.OBJECT_IDENTIFIER.ref(), true, false ) ); classType.add( new TypeFieldType( "&Type", false, null ) ); classType.add( new TypeFieldType( "&TypeConstraint", false, null ) ); classType.validate( module.createScope() ); Ref<Value> ref = new AbstractSyntaxObjectRef( "{ My-Module.Type-External IDENTIFIED BY { rootOid 3 } CONSTRAINED BY TYPE-Constraint}" ); Value value = ref.resolve( classType.getScope( module.createScope() ) ); Assert.assertNotNull( "No result", value ); }
@Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); @Override Value resolve( Scope scope ); }
AbstractSyntaxObjectRef implements Ref<Value> { @Override public Value resolve( Scope scope ) throws ResolutionException { Type type = scope.getTypeOrDie(); while( type != null && !( type instanceof ClassType ) ) type = type.hasSibling() ? type.getSibling() : null; if( type == null ) throw new ResolutionException( "Unable to find ClassType" ); Module module = scope.getModule(); ModuleResolver resolver = module.getModuleResolver(); assert resolver != null; ClassType classType = (ClassType)type; try { AbstractSyntaxParser parser = new AbstractSyntaxParser( module, classType ); Map<String, Ref<?>> result = parser.parse( abstractSyntax ); return new ObjectValue( result ); } catch( AbstractSyntaxParserException e ) { throw new ResolutionException( "Unable to unwrap abstract syntax: " + abstractSyntax, e ); } } AbstractSyntaxObjectRef( String abstractSyntax ); @Override Value resolve( Scope scope ); }
@Test( expected = AssertionError.class ) public void testDecode_fail_type() throws Exception { Scope scope = CoreModule.getInstance().createScope(); Type type = UniversalType.INTEGER.ref().resolve( scope ); try( AbstractBerReader reader = mock( DefaultBerReader.class ) ) { Tag tag = ( (TagEncoding)type.getEncoding( EncodingInstructions.TAG ) ).toTag( false ); new NullBerDecoder().decode( new ReaderContext( reader, scope, type, tag, 0, false ) ); fail( "Must fail" ); } }
@Override public Value decode( @NotNull ReaderContext context ) { assert context.getType().getFamily() == Family.NULL; assert context.getLength() == 0; return NullValue.INSTANCE; }
NullBerDecoder implements BerDecoder { @Override public Value decode( @NotNull ReaderContext context ) { assert context.getType().getFamily() == Family.NULL; assert context.getLength() == 0; return NullValue.INSTANCE; } }
NullBerDecoder implements BerDecoder { @Override public Value decode( @NotNull ReaderContext context ) { assert context.getType().getFamily() == Family.NULL; assert context.getLength() == 0; return NullValue.INSTANCE; } }
NullBerDecoder implements BerDecoder { @Override public Value decode( @NotNull ReaderContext context ) { assert context.getType().getFamily() == Family.NULL; assert context.getLength() == 0; return NullValue.INSTANCE; } @Override Value decode( @NotNull ReaderContext context ); }
NullBerDecoder implements BerDecoder { @Override public Value decode( @NotNull ReaderContext context ) { assert context.getType().getFamily() == Family.NULL; assert context.getLength() == 0; return NullValue.INSTANCE; } @Override Value decode( @NotNull ReaderContext context ); }
@Test public void testFileQueue() throws IOException { FileQueueService fileQueueService = new FileQueueService(getTempFilePath()); fileQueueService.getQueueFile().add("test".getBytes()); assertThat(fileQueueService.getQueueFile().peek(), is("test".getBytes())); }
public QueueFile getQueueFile() { return this.queueFile; }
FileQueueService { public QueueFile getQueueFile() { return this.queueFile; } }
FileQueueService { public QueueFile getQueueFile() { return this.queueFile; } @Autowired FileQueueService(@Value("${modum.tokenapp.email.queue-file-path}") String queueFilePath, @Autowired ObjectMapper objectMapper); FileQueueService(String queueFilePath); FileQueueService(); }
FileQueueService { public QueueFile getQueueFile() { return this.queueFile; } @Autowired FileQueueService(@Value("${modum.tokenapp.email.queue-file-path}") String queueFilePath, @Autowired ObjectMapper objectMapper); FileQueueService(String queueFilePath); FileQueueService(); QueueFile getQueueFile(); ObjectMapper getObjectMapper(); synchronized void addConfirmationEmail(Investor investor, URI confirmationEmaiLink); synchronized void addSummaryEmail(Investor investor); synchronized Optional<Email> peekEmail(); synchronized void addEmail(Email email); }
FileQueueService { public QueueFile getQueueFile() { return this.queueFile; } @Autowired FileQueueService(@Value("${modum.tokenapp.email.queue-file-path}") String queueFilePath, @Autowired ObjectMapper objectMapper); FileQueueService(String queueFilePath); FileQueueService(); QueueFile getQueueFile(); ObjectMapper getObjectMapper(); synchronized void addConfirmationEmail(Investor investor, URI confirmationEmaiLink); synchronized void addSummaryEmail(Investor investor); synchronized Optional<Email> peekEmail(); synchronized void addEmail(Email email); }
@Test public void testMintingLarge() throws ExecutionException, InterruptedException { dataBtc(1).dataBtc(2); rateBtc(101, 1_050_000); rateBtc(102, 7); int current = 0; current = minting.mint(current, 100, 0, 1 * 100_000_000, 0, "w1"); Assert.assertEquals(2_100_000, current); current = minting.mint(current, 102, 0, 1 * 100_000_000, 0, "w2"); Assert.assertEquals(2_100_010, current); Iterator<Token> it = tokenRepository.findAllByOrderByWalletAddress().iterator(); Assert.assertEquals(2_100_000, it.next().getAmount().intValue()); Assert.assertEquals((int) (10), it.next().getAmount().intValue()); }
public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } @Transactional List<Payin> payin(); @Transactional List<Token> calc(List<Payin> list); void mint(List<Token> tokens); @Transactional int mint(int current, long blockNrBTC, long blockNrETH, long satoshi, long wei, String walletAddress); void mintFinished(); }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } @Transactional List<Payin> payin(); @Transactional List<Token> calc(List<Payin> list); void mint(List<Token> tokens); @Transactional int mint(int current, long blockNrBTC, long blockNrETH, long satoshi, long wei, String walletAddress); void mintFinished(); }
@Test public void testMintingLarge2() throws ExecutionException, InterruptedException { dataBtc(1).dataBtc(2); rateBtc(101, 1_050_001); rateBtc(102, 7); int current = 0; current = minting.mint(current, 100, 0, 1 * 100_000_000, 0, "w1"); Assert.assertEquals(0, current); current = minting.mint(current, 102, 0, 1 * 100_000_000, 0, "w2"); Assert.assertEquals(14, current); Iterator<Token> it = tokenRepository.findAllByOrderByWalletAddress().iterator(); Assert.assertEquals(14, it.next().getAmount().intValue()); }
public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } @Transactional List<Payin> payin(); @Transactional List<Token> calc(List<Payin> list); void mint(List<Token> tokens); @Transactional int mint(int current, long blockNrBTC, long blockNrETH, long satoshi, long wei, String walletAddress); void mintFinished(); }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } @Transactional List<Payin> payin(); @Transactional List<Token> calc(List<Payin> list); void mint(List<Token> tokens); @Transactional int mint(int current, long blockNrBTC, long blockNrETH, long satoshi, long wei, String walletAddress); void mintFinished(); }
@Test public void testMinting() throws ExecutionException, InterruptedException { dataBtc(1).dataBtc(2); rateBtc(101, 1_050_000); rateBtc(102, 1_470_000); rateBtc(103, 1_785_000); rateBtc(104, 2_100_000); rateBtc(105, 1); int current = 0; current = minting.mint(current, 100, 0, 1 * 100_000_000, 0, "w1"); Assert.assertEquals(2_100_000, current); current = minting.mint(current, 102, 0, 1 * 100_000_000, 0, "w1"); Assert.assertEquals(4_200_000, current); current = minting.mint(current, 102, 0, 1 * 100_000_000, 0, "w1"); Assert.assertEquals(6_300_000, current); current = minting.mint(current, 102, 0, 1 * 100_000_000, 0, "w1"); Assert.assertEquals(8_347_058, current); current = minting.mint(current, 103, 0, 1 * 100_000_000, 0, "w1"); Assert.assertEquals(10_447_058, current); current = minting.mint(current, 103, 0, 1 * 100_000_000, 0, "w1"); Assert.assertEquals(12_547_058, current); current = minting.mint(current, 103, 0, 1 * 100_000_000, 0, "w1"); Assert.assertEquals(14_564_999, current); current = minting.mint(current, 104, 0, 1 * 100_000_000, 0, "w1"); Assert.assertEquals(16_664_999, current); current = minting.mint(current, 104, 0, 1 * 100_000_000, 0, "w1"); Assert.assertEquals(18_764_999, current); current = minting.mint(current, 104, 0, 1 * 100_000_000, 0, "w1"); Assert.assertEquals(20_100_000, current); current = minting.mint(current, 105, 0, 1 * 100_000_000, 0, "w1"); Assert.assertEquals(20_100_000, current); for(Token token:tokenRepository.findAll()) { System.out.println(token.getAmount()+" / "+token.getWalletAddress()); } }
public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } @Transactional List<Payin> payin(); @Transactional List<Token> calc(List<Payin> list); void mint(List<Token> tokens); @Transactional int mint(int current, long blockNrBTC, long blockNrETH, long satoshi, long wei, String walletAddress); void mintFinished(); }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } @Transactional List<Payin> payin(); @Transactional List<Token> calc(List<Payin> list); void mint(List<Token> tokens); @Transactional int mint(int current, long blockNrBTC, long blockNrETH, long satoshi, long wei, String walletAddress); void mintFinished(); }
@Test public void testFileQueueRecovering() throws IOException { String tempFile = getTempFilePath(); FileQueueService fileQueueService1 = new FileQueueService(tempFile); fileQueueService1.getQueueFile().add("test".getBytes()); FileQueueService fileQueueService2 = new FileQueueService(tempFile); assertThat(fileQueueService2.getQueueFile().peek(), is("test".getBytes())); }
public QueueFile getQueueFile() { return this.queueFile; }
FileQueueService { public QueueFile getQueueFile() { return this.queueFile; } }
FileQueueService { public QueueFile getQueueFile() { return this.queueFile; } @Autowired FileQueueService(@Value("${modum.tokenapp.email.queue-file-path}") String queueFilePath, @Autowired ObjectMapper objectMapper); FileQueueService(String queueFilePath); FileQueueService(); }
FileQueueService { public QueueFile getQueueFile() { return this.queueFile; } @Autowired FileQueueService(@Value("${modum.tokenapp.email.queue-file-path}") String queueFilePath, @Autowired ObjectMapper objectMapper); FileQueueService(String queueFilePath); FileQueueService(); QueueFile getQueueFile(); ObjectMapper getObjectMapper(); synchronized void addConfirmationEmail(Investor investor, URI confirmationEmaiLink); synchronized void addSummaryEmail(Investor investor); synchronized Optional<Email> peekEmail(); synchronized void addEmail(Email email); }
FileQueueService { public QueueFile getQueueFile() { return this.queueFile; } @Autowired FileQueueService(@Value("${modum.tokenapp.email.queue-file-path}") String queueFilePath, @Autowired ObjectMapper objectMapper); FileQueueService(String queueFilePath); FileQueueService(); QueueFile getQueueFile(); ObjectMapper getObjectMapper(); synchronized void addConfirmationEmail(Investor investor, URI confirmationEmaiLink); synchronized void addSummaryEmail(Investor investor); synchronized Optional<Email> peekEmail(); synchronized void addEmail(Email email); }
@Test public void testSendEmailTask() throws IOException, URISyntaxException { FileQueueService fileQueueService = new FileQueueService(getTempFilePath(), objectMapper); fileQueueService.addConfirmationEmail(new Investor().setEmail(INVESTOR_EMAIL), new URI(CONFIRMATION_EMAIL_URI)); Email email = fileQueueService.peekEmail().get(); assertThat(email.getInvestor().getEmail(), is(INVESTOR_EMAIL)); assertThat(email.getConfirmationEmaiLink().toASCIIString(), is(CONFIRMATION_EMAIL_URI)); }
public SendEmailTask() { }
SendEmailTask { public SendEmailTask() { } }
SendEmailTask { public SendEmailTask() { } SendEmailTask(); }
SendEmailTask { public SendEmailTask() { } SendEmailTask(); @Scheduled(initialDelay = 10000, fixedRateString = "${modum.tokenapp.email.send-email-interval}") void sendEmail(); }
SendEmailTask { public SendEmailTask() { } SendEmailTask(); @Scheduled(initialDelay = 10000, fixedRateString = "${modum.tokenapp.email.send-email-interval}") void sendEmail(); }
@Test public void testConnect1() throws IOException { String balance = etherscan.getBalance("0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae").toString(); System.out.println("balance: "+balance); }
public BigInteger getBalance(String address) throws IOException { String s = "https: "?module=account" + "&action=balance" + "&address=" + address + "&tag=latest" + "&apikey="+apiKey; HttpHeaders headers = new HttpHeaders(); headers.set("User-Agent", options.getUserAgent()); ResponseEntity<String> res = restTemplate.exchange(s, HttpMethod.GET, new HttpEntity<>(null, headers), String.class); ObjectMapper objectMapper = new ObjectMapper(); ReturnSingleValue retVal = objectMapper.readValue(res.getBody(), ReturnSingleValue.class); return new BigInteger(retVal.result); }
Etherscan { public BigInteger getBalance(String address) throws IOException { String s = "https: "?module=account" + "&action=balance" + "&address=" + address + "&tag=latest" + "&apikey="+apiKey; HttpHeaders headers = new HttpHeaders(); headers.set("User-Agent", options.getUserAgent()); ResponseEntity<String> res = restTemplate.exchange(s, HttpMethod.GET, new HttpEntity<>(null, headers), String.class); ObjectMapper objectMapper = new ObjectMapper(); ReturnSingleValue retVal = objectMapper.readValue(res.getBody(), ReturnSingleValue.class); return new BigInteger(retVal.result); } }
Etherscan { public BigInteger getBalance(String address) throws IOException { String s = "https: "?module=account" + "&action=balance" + "&address=" + address + "&tag=latest" + "&apikey="+apiKey; HttpHeaders headers = new HttpHeaders(); headers.set("User-Agent", options.getUserAgent()); ResponseEntity<String> res = restTemplate.exchange(s, HttpMethod.GET, new HttpEntity<>(null, headers), String.class); ObjectMapper objectMapper = new ObjectMapper(); ReturnSingleValue retVal = objectMapper.readValue(res.getBody(), ReturnSingleValue.class); return new BigInteger(retVal.result); } }
Etherscan { public BigInteger getBalance(String address) throws IOException { String s = "https: "?module=account" + "&action=balance" + "&address=" + address + "&tag=latest" + "&apikey="+apiKey; HttpHeaders headers = new HttpHeaders(); headers.set("User-Agent", options.getUserAgent()); ResponseEntity<String> res = restTemplate.exchange(s, HttpMethod.GET, new HttpEntity<>(null, headers), String.class); ObjectMapper objectMapper = new ObjectMapper(); ReturnSingleValue retVal = objectMapper.readValue(res.getBody(), ReturnSingleValue.class); return new BigInteger(retVal.result); } BigInteger getBalance(String address); List<Triple<Date,Long,Long>> getTxEth(String address); BigInteger get20Balances(String... contract); BigInteger get20Balances(List<String> contract); long getCurrentBlockNr(); BigInteger getBalances(List<String> contract); }
Etherscan { public BigInteger getBalance(String address) throws IOException { String s = "https: "?module=account" + "&action=balance" + "&address=" + address + "&tag=latest" + "&apikey="+apiKey; HttpHeaders headers = new HttpHeaders(); headers.set("User-Agent", options.getUserAgent()); ResponseEntity<String> res = restTemplate.exchange(s, HttpMethod.GET, new HttpEntity<>(null, headers), String.class); ObjectMapper objectMapper = new ObjectMapper(); ReturnSingleValue retVal = objectMapper.readValue(res.getBody(), ReturnSingleValue.class); return new BigInteger(retVal.result); } BigInteger getBalance(String address); List<Triple<Date,Long,Long>> getTxEth(String address); BigInteger get20Balances(String... contract); BigInteger get20Balances(List<String> contract); long getCurrentBlockNr(); BigInteger getBalances(List<String> contract); }
@Test public void testConnect2() throws IOException { String balance = etherscan.get20Balances("0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae", "0x25d96310cd6694d88b9c6803be09511597c0a630").toString(); System.out.println("balance: "+balance); }
public BigInteger get20Balances(String... contract) throws IOException { return get20Balances(Arrays.asList(contract)); }
Etherscan { public BigInteger get20Balances(String... contract) throws IOException { return get20Balances(Arrays.asList(contract)); } }
Etherscan { public BigInteger get20Balances(String... contract) throws IOException { return get20Balances(Arrays.asList(contract)); } }
Etherscan { public BigInteger get20Balances(String... contract) throws IOException { return get20Balances(Arrays.asList(contract)); } BigInteger getBalance(String address); List<Triple<Date,Long,Long>> getTxEth(String address); BigInteger get20Balances(String... contract); BigInteger get20Balances(List<String> contract); long getCurrentBlockNr(); BigInteger getBalances(List<String> contract); }
Etherscan { public BigInteger get20Balances(String... contract) throws IOException { return get20Balances(Arrays.asList(contract)); } BigInteger getBalance(String address); List<Triple<Date,Long,Long>> getTxEth(String address); BigInteger get20Balances(String... contract); BigInteger get20Balances(List<String> contract); long getCurrentBlockNr(); BigInteger getBalances(List<String> contract); }
@Test public void testBlockNr() throws IOException { long bl1 = blockr.getCurrentBlockNr(); long bl2 = etherscan.getCurrentBlockNr(); System.out.println("ret: "+bl1 +"/"+bl2); }
public long getCurrentBlockNr() throws IOException { String s = "https: "?module=proxy" + "&action=eth_blockNumber" + "&apikey="+apiKey; HttpHeaders headers = new HttpHeaders(); headers.set("User-Agent", options.getUserAgent()); ResponseEntity<String> res = restTemplate.exchange(s, HttpMethod.GET, new HttpEntity<>(null, headers), String.class); ObjectMapper objectMapper = new ObjectMapper(); ReturnBlock retVal = objectMapper.readValue(res.getBody(), ReturnBlock.class); return Long.parseLong(retVal.result.substring(2), 16); }
Etherscan { public long getCurrentBlockNr() throws IOException { String s = "https: "?module=proxy" + "&action=eth_blockNumber" + "&apikey="+apiKey; HttpHeaders headers = new HttpHeaders(); headers.set("User-Agent", options.getUserAgent()); ResponseEntity<String> res = restTemplate.exchange(s, HttpMethod.GET, new HttpEntity<>(null, headers), String.class); ObjectMapper objectMapper = new ObjectMapper(); ReturnBlock retVal = objectMapper.readValue(res.getBody(), ReturnBlock.class); return Long.parseLong(retVal.result.substring(2), 16); } }
Etherscan { public long getCurrentBlockNr() throws IOException { String s = "https: "?module=proxy" + "&action=eth_blockNumber" + "&apikey="+apiKey; HttpHeaders headers = new HttpHeaders(); headers.set("User-Agent", options.getUserAgent()); ResponseEntity<String> res = restTemplate.exchange(s, HttpMethod.GET, new HttpEntity<>(null, headers), String.class); ObjectMapper objectMapper = new ObjectMapper(); ReturnBlock retVal = objectMapper.readValue(res.getBody(), ReturnBlock.class); return Long.parseLong(retVal.result.substring(2), 16); } }
Etherscan { public long getCurrentBlockNr() throws IOException { String s = "https: "?module=proxy" + "&action=eth_blockNumber" + "&apikey="+apiKey; HttpHeaders headers = new HttpHeaders(); headers.set("User-Agent", options.getUserAgent()); ResponseEntity<String> res = restTemplate.exchange(s, HttpMethod.GET, new HttpEntity<>(null, headers), String.class); ObjectMapper objectMapper = new ObjectMapper(); ReturnBlock retVal = objectMapper.readValue(res.getBody(), ReturnBlock.class); return Long.parseLong(retVal.result.substring(2), 16); } BigInteger getBalance(String address); List<Triple<Date,Long,Long>> getTxEth(String address); BigInteger get20Balances(String... contract); BigInteger get20Balances(List<String> contract); long getCurrentBlockNr(); BigInteger getBalances(List<String> contract); }
Etherscan { public long getCurrentBlockNr() throws IOException { String s = "https: "?module=proxy" + "&action=eth_blockNumber" + "&apikey="+apiKey; HttpHeaders headers = new HttpHeaders(); headers.set("User-Agent", options.getUserAgent()); ResponseEntity<String> res = restTemplate.exchange(s, HttpMethod.GET, new HttpEntity<>(null, headers), String.class); ObjectMapper objectMapper = new ObjectMapper(); ReturnBlock retVal = objectMapper.readValue(res.getBody(), ReturnBlock.class); return Long.parseLong(retVal.result.substring(2), 16); } BigInteger getBalance(String address); List<Triple<Date,Long,Long>> getTxEth(String address); BigInteger get20Balances(String... contract); BigInteger get20Balances(List<String> contract); long getCurrentBlockNr(); BigInteger getBalances(List<String> contract); }
@Test public void testMintingRate() throws ExecutionException, InterruptedException { dataBtc(1); rateBtc(99, 1); rateBtc(100, 1000); rateBtc(101, 3000); int current = 0; current = minting.mint(current, 100, 0, 1 * 100_000_000, 0, "w1"); Assert.assertEquals(2000, current); Token token = tokenRepository.findAllByOrderByWalletAddress().iterator().next(); Assert.assertEquals(2000, token.getAmount().intValue()); }
public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } @Transactional List<Payin> payin(); @Transactional List<Token> calc(List<Payin> list); void mint(List<Token> tokens); @Transactional int mint(int current, long blockNrBTC, long blockNrETH, long satoshi, long wei, String walletAddress); void mintFinished(); }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } @Transactional List<Payin> payin(); @Transactional List<Token> calc(List<Payin> list); void mint(List<Token> tokens); @Transactional int mint(int current, long blockNrBTC, long blockNrETH, long satoshi, long wei, String walletAddress); void mintFinished(); }
@Test public void testMintingRateMissing() throws ExecutionException, InterruptedException { dataBtc(1); rateBtc(99, 1); rateBtc(101, 3000); int current = 0; current = minting.mint(current, 100, 0, 1 * 100_000_000, 0, "w1"); Assert.assertEquals(6000, current); Token token = tokenRepository.findAllByOrderByWalletAddress().iterator().next(); Assert.assertEquals(6000, token.getAmount().intValue()); }
public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } @Transactional List<Payin> payin(); @Transactional List<Token> calc(List<Payin> list); void mint(List<Token> tokens); @Transactional int mint(int current, long blockNrBTC, long blockNrETH, long satoshi, long wei, String walletAddress); void mintFinished(); }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } @Transactional List<Payin> payin(); @Transactional List<Token> calc(List<Payin> list); void mint(List<Token> tokens); @Transactional int mint(int current, long blockNrBTC, long blockNrETH, long satoshi, long wei, String walletAddress); void mintFinished(); }
@Test public void testMintingBoundary() throws ExecutionException, InterruptedException { dataBtc(1).dataBtc(2); rateBtc(101, 1_049_999); rateBtc(102, 3); int current = 0; current = minting.mint(current, 100, 0, 1 * 100_000_000, 0, "w1"); Assert.assertEquals(2_099_998, current); current = minting.mint(current, 102, 0, 1 * 100_000_000, 0, "w2"); Assert.assertEquals(2_100_002, current); Iterator<Token> it = tokenRepository.findAllByOrderByWalletAddress().iterator(); Assert.assertEquals(2_099_998, it.next().getAmount().intValue()); Assert.assertEquals((int) (2 + 2.85), it.next().getAmount().intValue()); }
public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } @Transactional List<Payin> payin(); @Transactional List<Token> calc(List<Payin> list); void mint(List<Token> tokens); @Transactional int mint(int current, long blockNrBTC, long blockNrETH, long satoshi, long wei, String walletAddress); void mintFinished(); }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } @Transactional List<Payin> payin(); @Transactional List<Token> calc(List<Payin> list); void mint(List<Token> tokens); @Transactional int mint(int current, long blockNrBTC, long blockNrETH, long satoshi, long wei, String walletAddress); void mintFinished(); }
@Test public void testMintingBoundary2() throws ExecutionException, InterruptedException { dataBtc(1).dataBtc(2); rateBtc(101, 1_049_999); rateBtc(102, 8); int current = 0; current = minting.mint(current, 100, 0, 1 * 100_000_000, 0, "w1"); Assert.assertEquals(2_099_998, current); current = minting.mint(current, 102, 0, 1 * 100_000_000, 0, "w2"); Assert.assertEquals(2_100_010, current); Iterator<Token> it = tokenRepository.findAllByOrderByWalletAddress().iterator(); Assert.assertEquals(2_099_998, it.next().getAmount().intValue()); Assert.assertEquals((int) (2 + 10), it.next().getAmount().intValue()); }
public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } @Transactional List<Payin> payin(); @Transactional List<Token> calc(List<Payin> list); void mint(List<Token> tokens); @Transactional int mint(int current, long blockNrBTC, long blockNrETH, long satoshi, long wei, String walletAddress); void mintFinished(); }
Minting { public void mint(List<Token> tokens) throws ExecutionException, InterruptedException { for(Token token:tokens) { if(modumToken == null) { LOG.error("no modum token bean created"); } else { Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount())); receipt.get(); LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount()); } } } @Transactional List<Payin> payin(); @Transactional List<Token> calc(List<Payin> list); void mint(List<Token> tokens); @Transactional int mint(int current, long blockNrBTC, long blockNrETH, long satoshi, long wei, String walletAddress); void mintFinished(); }
@Test public void twoByteEncoding() throws IOException { BerByteArrayOutputStream berBAOStream = new BerByteArrayOutputStream(50); BerIdentifier berIdentifier = new BerIdentifier(BerIdentifier.APPLICATION_CLASS, BerIdentifier.PRIMITIVE, 31); int length = berIdentifier.encode(berBAOStream); Assert.assertEquals(2, length); byte[] expectedBytes = new byte[] { 0x5f, 0x1f }; Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
public int encode(BerByteArrayOutputStream berOStream) throws IOException { for (int i = (identifier.length - 1); i >= 0; i--) { berOStream.write(identifier[i]); } return identifier.length; }
BerIdentifier { public int encode(BerByteArrayOutputStream berOStream) throws IOException { for (int i = (identifier.length - 1); i >= 0; i--) { berOStream.write(identifier[i]); } return identifier.length; } }
BerIdentifier { public int encode(BerByteArrayOutputStream berOStream) throws IOException { for (int i = (identifier.length - 1); i >= 0; i--) { berOStream.write(identifier[i]); } return identifier.length; } BerIdentifier(int identifierClass, int primitive, int tagNumber); BerIdentifier(); }
BerIdentifier { public int encode(BerByteArrayOutputStream berOStream) throws IOException { for (int i = (identifier.length - 1); i >= 0; i--) { berOStream.write(identifier[i]); } return identifier.length; } BerIdentifier(int identifierClass, int primitive, int tagNumber); BerIdentifier(); int encode(BerByteArrayOutputStream berOStream); int decode(InputStream iStream); int decodeAndCheck(InputStream iStream); boolean equals(int identifierClass, int primitive, int tagNumber); boolean equals(BerIdentifier berIdentifier); @Override String toString(); }
BerIdentifier { public int encode(BerByteArrayOutputStream berOStream) throws IOException { for (int i = (identifier.length - 1); i >= 0; i--) { berOStream.write(identifier[i]); } return identifier.length; } BerIdentifier(int identifierClass, int primitive, int tagNumber); BerIdentifier(); int encode(BerByteArrayOutputStream berOStream); int decode(InputStream iStream); int decodeAndCheck(InputStream iStream); boolean equals(int identifierClass, int primitive, int tagNumber); boolean equals(BerIdentifier berIdentifier); @Override String toString(); static final int UNIVERSAL_CLASS; static final int APPLICATION_CLASS; static final int CONTEXT_CLASS; static final int PRIVATE_CLASS; static final int PRIMITIVE; static final int CONSTRUCTED; static final int BOOLEAN_TAG; static final int INTEGER_TAG; static final int BIT_STRING_TAG; static final int OCTET_STRING_TAG; static final int NULL_TAG; static final int OBJECT_IDENTIFIER_TAG; static final int REAL_TAG; static final int ENUMERATED_TAG; static final int UTF8_STRING_TAG; static final int NUMERIC_STRING_TAG; static final int PRINTABLE_STRING_TAG; static final int TELETEX_STRING_TAG; static final int VIDEOTEX_STRING_TAG; static final int IA5_STRING_TAG; static final int GENERALIZED_TIME_TAG; static final int GRAPHIC_STRING_TAG; static final int VISIBLE_STRING_TAG; static final int GENERAL_STRING_TAG; static final int UNIVERSAL_STRING_TAG; static final int BMP_STRING_TAG; public byte[] identifier; public int identifierClass; public int primitive; public int tagNumber; }
@Test public void implicitEncoding7() throws IOException { BerByteArrayOutputStream berBAOStream = new BerByteArrayOutputStream(50); IntegerUnivPrim testInteger = new IntegerUnivPrim(-129); int length = testInteger.encode(berBAOStream, false); Assert.assertEquals(3, length); byte[] expectedBytes = new byte[] { 0x02, (byte) 0xff, (byte) 0x7f }; Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); final static BerIdentifier identifier; public BerIdentifier id; public byte[] code; public long val; }
@Test public void explicitEncoding() throws IOException { BerByteArrayOutputStream berStream = new BerByteArrayOutputStream(50); BerInteger testInteger = new BerInteger(51); int length = testInteger.encode(berStream, true); Assert.assertEquals(3, length); byte[] expectedBytes = new byte[] { 0x02, 0x01, 0x33 }; Assert.assertArrayEquals(expectedBytes, berStream.getArray()); }
public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); final static BerIdentifier identifier; public BerIdentifier id; public byte[] code; public long val; }
@Test public void explicitDecoding() throws IOException { byte[] byteCode = new byte[] { 0x02, 0x01, 0x33 }; ByteArrayInputStream berInputStream = new ByteArrayInputStream(byteCode); BerInteger asn1Integer = new BerInteger(); asn1Integer.decode(berInputStream, true); Assert.assertEquals(51, asn1Integer.val); }
public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; }
BerInteger { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; } }
BerInteger { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); }
BerInteger { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); }
BerInteger { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); final static BerIdentifier identifier; public BerIdentifier id; public byte[] code; public long val; }
@Test public void explicitEncoding2() throws IOException { BerByteArrayOutputStream berStream = new BerByteArrayOutputStream(50); BerInteger testInteger = new BerInteger(5555); int length = testInteger.encode(berStream, true); Assert.assertEquals(4, length); byte[] expectedBytes = new byte[] { 0x02, 0x02, 0x15, (byte) 0xb3 }; Assert.assertArrayEquals(expectedBytes, berStream.getArray()); }
public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); final static BerIdentifier identifier; public BerIdentifier id; public byte[] code; public long val; }
@Test public void explicitDecoding2() throws IOException { byte[] byteCode = new byte[] { 0x02, 0x02, 0x15, (byte) 0xb3 }; ByteArrayInputStream berInputStream = new ByteArrayInputStream(byteCode); BerInteger asn1Integer = new BerInteger(); asn1Integer.decode(berInputStream, true); Assert.assertEquals(5555, asn1Integer.val); }
public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; }
BerInteger { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; } }
BerInteger { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); }
BerInteger { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); }
BerInteger { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); final static BerIdentifier identifier; public BerIdentifier id; public byte[] code; public long val; }
@Test public void explicitDecoding3() throws IOException { byte[] byteCode = new byte[] { 0x02, 0x01, (byte) 0xc0 }; ByteArrayInputStream berInputStream = new ByteArrayInputStream(byteCode); BerInteger asn1Integer = new BerInteger(); asn1Integer.decode(berInputStream, true); Assert.assertEquals(-64, asn1Integer.val); }
public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; }
BerInteger { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; } }
BerInteger { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); }
BerInteger { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); }
BerInteger { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); final static BerIdentifier identifier; public BerIdentifier id; public byte[] code; public long val; }
@Test public void explicitDecoding4() throws IOException { byte[] byteCode = new byte[] { 0x02, 0x02, (byte) 0xff, 0x01 }; ByteArrayInputStream berInputStream = new ByteArrayInputStream(byteCode); BerInteger asn1Integer = new BerInteger(); asn1Integer.decode(berInputStream, true); Assert.assertEquals(-255, asn1Integer.val); }
public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; }
BerInteger { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; } }
BerInteger { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); }
BerInteger { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); }
BerInteger { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val < 1 || length.val > 8) { throw new IOException("Decoded length of BerInteger is not correct"); } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) < length.val) { throw new IOException("Error Decoding BerInteger"); } codeLength += length.val; val = (byteCode[0] & 0x80) == 0x80 ? -1 : 0; for (int i = 0; i < length.val; i++) { val <<= 8; val |= byteCode[i] & 0xff; } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); final static BerIdentifier identifier; public BerIdentifier id; public byte[] code; public long val; }
@Test public void explicitEncoding() throws IOException { BerByteArrayOutputStream berStream = new BerByteArrayOutputStream(50); byte[] byteArray = new byte[] { 0x01, 0x02, 0x03 }; BerOctetString asn1OctetString = new BerOctetString(byteArray); int length = asn1OctetString.encode(berStream, true); Assert.assertEquals(5, length); byte[] expectedBytes = new byte[] { 0x04, 0x03, 0x01, 0x02, 0x03 }; Assert.assertArrayEquals(expectedBytes, berStream.getArray()); }
public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { berOStream.write(octetString); int codeLength = octetString.length; codeLength += BerLength.encodeLength(berOStream, codeLength); if (explicit) { codeLength += id.encode(berOStream); } return codeLength; }
BerOctetString { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { berOStream.write(octetString); int codeLength = octetString.length; codeLength += BerLength.encodeLength(berOStream, codeLength); if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } }
BerOctetString { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { berOStream.write(octetString); int codeLength = octetString.length; codeLength += BerLength.encodeLength(berOStream, codeLength); if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerOctetString(); BerOctetString(byte[] octetString); }
BerOctetString { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { berOStream.write(octetString); int codeLength = octetString.length; codeLength += BerLength.encodeLength(berOStream, codeLength); if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerOctetString(); BerOctetString(byte[] octetString); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); @Override String toString(); }
BerOctetString { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { berOStream.write(octetString); int codeLength = octetString.length; codeLength += BerLength.encodeLength(berOStream, codeLength); if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerOctetString(); BerOctetString(byte[] octetString); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); @Override String toString(); final static BerIdentifier identifier; public byte[] octetString; }
@Test public void explicitDecoding() throws IOException { byte[] byteCode = new byte[] { 0x04, 0x00 }; ByteArrayInputStream berInputStream = new ByteArrayInputStream(byteCode); BerOctetString asn1OctetString = new BerOctetString(); asn1OctetString.decode(berInputStream, true); Assert.assertEquals(0, asn1OctetString.octetString.length); }
public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); octetString = new byte[length.val]; if (length.val != 0) { if (iStream.read(octetString, 0, length.val) < length.val) { throw new IOException("Error Decoding BerOctetString"); } codeLength += length.val; } return codeLength; }
BerOctetString { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); octetString = new byte[length.val]; if (length.val != 0) { if (iStream.read(octetString, 0, length.val) < length.val) { throw new IOException("Error Decoding BerOctetString"); } codeLength += length.val; } return codeLength; } }
BerOctetString { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); octetString = new byte[length.val]; if (length.val != 0) { if (iStream.read(octetString, 0, length.val) < length.val) { throw new IOException("Error Decoding BerOctetString"); } codeLength += length.val; } return codeLength; } BerOctetString(); BerOctetString(byte[] octetString); }
BerOctetString { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); octetString = new byte[length.val]; if (length.val != 0) { if (iStream.read(octetString, 0, length.val) < length.val) { throw new IOException("Error Decoding BerOctetString"); } codeLength += length.val; } return codeLength; } BerOctetString(); BerOctetString(byte[] octetString); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); @Override String toString(); }
BerOctetString { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); octetString = new byte[length.val]; if (length.val != 0) { if (iStream.read(octetString, 0, length.val) < length.val) { throw new IOException("Error Decoding BerOctetString"); } codeLength += length.val; } return codeLength; } BerOctetString(); BerOctetString(byte[] octetString); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); @Override String toString(); final static BerIdentifier identifier; public byte[] octetString; }
@Test public void explicitEncoding() throws IOException { BerByteArrayOutputStream berBAOStream = new BerByteArrayOutputStream(50); BerObjectIdentifier oi = new BerObjectIdentifier(objectIdentifierComponents); int length = oi.encode(berBAOStream, true); Assert.assertEquals(7, length); Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { int firstSubidentifier = 40 * objectIdentifierComponents[0] + objectIdentifierComponents[1]; int subidentifier; codeLength = 0; for (int i = (objectIdentifierComponents.length - 1); i > 0; i--) { if (i == 1) { subidentifier = firstSubidentifier; } else { subidentifier = objectIdentifierComponents[i]; } int subIDLength = 1; while (subidentifier > (Math.pow(2, (7 * subIDLength)) - 1)) { subIDLength++; } berOStream.write(subidentifier & 0x7f); for (int j = 1; j <= (subIDLength - 1); j++) { berOStream.write(((subidentifier >> (7 * j)) & 0xff) | 0x80); } codeLength += subIDLength; } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; }
BerObjectIdentifier { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { int firstSubidentifier = 40 * objectIdentifierComponents[0] + objectIdentifierComponents[1]; int subidentifier; codeLength = 0; for (int i = (objectIdentifierComponents.length - 1); i > 0; i--) { if (i == 1) { subidentifier = firstSubidentifier; } else { subidentifier = objectIdentifierComponents[i]; } int subIDLength = 1; while (subidentifier > (Math.pow(2, (7 * subIDLength)) - 1)) { subIDLength++; } berOStream.write(subidentifier & 0x7f); for (int j = 1; j <= (subIDLength - 1); j++) { berOStream.write(((subidentifier >> (7 * j)) & 0xff) | 0x80); } codeLength += subIDLength; } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } }
BerObjectIdentifier { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { int firstSubidentifier = 40 * objectIdentifierComponents[0] + objectIdentifierComponents[1]; int subidentifier; codeLength = 0; for (int i = (objectIdentifierComponents.length - 1); i > 0; i--) { if (i == 1) { subidentifier = firstSubidentifier; } else { subidentifier = objectIdentifierComponents[i]; } int subIDLength = 1; while (subidentifier > (Math.pow(2, (7 * subIDLength)) - 1)) { subIDLength++; } berOStream.write(subidentifier & 0x7f); for (int j = 1; j <= (subIDLength - 1); j++) { berOStream.write(((subidentifier >> (7 * j)) & 0xff) | 0x80); } codeLength += subIDLength; } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerObjectIdentifier(); BerObjectIdentifier(byte[] code); BerObjectIdentifier(int[] objectIdentifierComponents); }
BerObjectIdentifier { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { int firstSubidentifier = 40 * objectIdentifierComponents[0] + objectIdentifierComponents[1]; int subidentifier; codeLength = 0; for (int i = (objectIdentifierComponents.length - 1); i > 0; i--) { if (i == 1) { subidentifier = firstSubidentifier; } else { subidentifier = objectIdentifierComponents[i]; } int subIDLength = 1; while (subidentifier > (Math.pow(2, (7 * subIDLength)) - 1)) { subIDLength++; } berOStream.write(subidentifier & 0x7f); for (int j = 1; j <= (subIDLength - 1); j++) { berOStream.write(((subidentifier >> (7 * j)) & 0xff) | 0x80); } codeLength += subIDLength; } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerObjectIdentifier(); BerObjectIdentifier(byte[] code); BerObjectIdentifier(int[] objectIdentifierComponents); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); @Override String toString(); }
BerObjectIdentifier { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { int firstSubidentifier = 40 * objectIdentifierComponents[0] + objectIdentifierComponents[1]; int subidentifier; codeLength = 0; for (int i = (objectIdentifierComponents.length - 1); i > 0; i--) { if (i == 1) { subidentifier = firstSubidentifier; } else { subidentifier = objectIdentifierComponents[i]; } int subIDLength = 1; while (subidentifier > (Math.pow(2, (7 * subIDLength)) - 1)) { subIDLength++; } berOStream.write(subidentifier & 0x7f); for (int j = 1; j <= (subIDLength - 1); j++) { berOStream.write(((subidentifier >> (7 * j)) & 0xff) | 0x80); } codeLength += subIDLength; } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerObjectIdentifier(); BerObjectIdentifier(byte[] code); BerObjectIdentifier(int[] objectIdentifierComponents); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); @Override String toString(); final static BerIdentifier identifier; public byte[] code; public int[] objectIdentifierComponents; }
@Test public void encodeLength() throws IOException { BerByteArrayOutputStream berOStream = new BerByteArrayOutputStream(50); int codedLength = BerLength.encodeLength(berOStream, 128); Assert.assertEquals(2, codedLength); byte[] expectedBytes = new byte[] { (byte) 0x81, (byte) 128 }; Assert.assertArrayEquals(expectedBytes, berOStream.getArray()); }
public static int encodeLength(BerByteArrayOutputStream berOStream, int length) throws IOException { if (length <= 127) { berOStream.write((byte) length); return 1; } else { int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { berOStream.write((length >> 8 * i) & 0xff); } berOStream.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } }
BerLength { public static int encodeLength(BerByteArrayOutputStream berOStream, int length) throws IOException { if (length <= 127) { berOStream.write((byte) length); return 1; } else { int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { berOStream.write((length >> 8 * i) & 0xff); } berOStream.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } } }
BerLength { public static int encodeLength(BerByteArrayOutputStream berOStream, int length) throws IOException { if (length <= 127) { berOStream.write((byte) length); return 1; } else { int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { berOStream.write((length >> 8 * i) & 0xff); } berOStream.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } } BerLength(); }
BerLength { public static int encodeLength(BerByteArrayOutputStream berOStream, int length) throws IOException { if (length <= 127) { berOStream.write((byte) length); return 1; } else { int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { berOStream.write((length >> 8 * i) & 0xff); } berOStream.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } } BerLength(); int decode(InputStream iStream); static int encodeLength(BerByteArrayOutputStream berOStream, int length); }
BerLength { public static int encodeLength(BerByteArrayOutputStream berOStream, int length) throws IOException { if (length <= 127) { berOStream.write((byte) length); return 1; } else { int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { berOStream.write((length >> 8 * i) & 0xff); } berOStream.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } } BerLength(); int decode(InputStream iStream); static int encodeLength(BerByteArrayOutputStream berOStream, int length); public int val; }
@Test public void explicitDecoding() throws IOException { ByteArrayInputStream berInputStream = new ByteArrayInputStream(expectedBytes); BerObjectIdentifier oi = new BerObjectIdentifier(); oi.decode(berInputStream, true); Assert.assertArrayEquals(objectIdentifierComponents, oi.objectIdentifierComponents); ByteArrayInputStream berInputStream2 = new ByteArrayInputStream(expectedBytes2); BerObjectIdentifier oi2 = new BerObjectIdentifier(); oi2.decode(berInputStream2, true); }
public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val == 0) { objectIdentifierComponents = new int[0]; return codeLength; } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) == -1) { throw new IOException("Error Decoding BerObjectIdentifier"); } codeLength += length.val; List<Integer> objectIdentifierComponentsList = new ArrayList<Integer>(); int subIDEndIndex = 0; while ((byteCode[subIDEndIndex] & 0x80) == 0x80) { if (subIDEndIndex >= (length.val - 1)) { throw new IOException("Invalid Object Identifier"); } subIDEndIndex++; } int subidentifier = 0; for (int i = 0; i <= subIDEndIndex; i++) { subidentifier |= (byteCode[i] << ((subIDEndIndex - i) * 7)); } if (subidentifier < 40) { objectIdentifierComponentsList.add(0); objectIdentifierComponentsList.add(subidentifier); } else if (subidentifier < 80) { objectIdentifierComponentsList.add(1); objectIdentifierComponentsList.add(subidentifier - 40); } else { objectIdentifierComponentsList.add(2); objectIdentifierComponentsList.add(subidentifier - 80); } subIDEndIndex++; while (subIDEndIndex < length.val) { int subIDStartIndex = subIDEndIndex; while ((byteCode[subIDEndIndex] & 0x80) == 0x80) { if (subIDEndIndex == (length.val - 1)) { throw new IOException("Invalid Object Identifier"); } subIDEndIndex++; } subidentifier = 0; for (int j = subIDStartIndex; j <= subIDEndIndex; j++) { subidentifier |= ((byteCode[j] & 0x7f) << ((subIDEndIndex - j) * 7)); } objectIdentifierComponentsList.add(subidentifier); subIDEndIndex++; } objectIdentifierComponents = new int[objectIdentifierComponentsList.size()]; for (int i = 0; i < objectIdentifierComponentsList.size(); i++) { objectIdentifierComponents[i] = objectIdentifierComponentsList.get(i); } return codeLength; }
BerObjectIdentifier { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val == 0) { objectIdentifierComponents = new int[0]; return codeLength; } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) == -1) { throw new IOException("Error Decoding BerObjectIdentifier"); } codeLength += length.val; List<Integer> objectIdentifierComponentsList = new ArrayList<Integer>(); int subIDEndIndex = 0; while ((byteCode[subIDEndIndex] & 0x80) == 0x80) { if (subIDEndIndex >= (length.val - 1)) { throw new IOException("Invalid Object Identifier"); } subIDEndIndex++; } int subidentifier = 0; for (int i = 0; i <= subIDEndIndex; i++) { subidentifier |= (byteCode[i] << ((subIDEndIndex - i) * 7)); } if (subidentifier < 40) { objectIdentifierComponentsList.add(0); objectIdentifierComponentsList.add(subidentifier); } else if (subidentifier < 80) { objectIdentifierComponentsList.add(1); objectIdentifierComponentsList.add(subidentifier - 40); } else { objectIdentifierComponentsList.add(2); objectIdentifierComponentsList.add(subidentifier - 80); } subIDEndIndex++; while (subIDEndIndex < length.val) { int subIDStartIndex = subIDEndIndex; while ((byteCode[subIDEndIndex] & 0x80) == 0x80) { if (subIDEndIndex == (length.val - 1)) { throw new IOException("Invalid Object Identifier"); } subIDEndIndex++; } subidentifier = 0; for (int j = subIDStartIndex; j <= subIDEndIndex; j++) { subidentifier |= ((byteCode[j] & 0x7f) << ((subIDEndIndex - j) * 7)); } objectIdentifierComponentsList.add(subidentifier); subIDEndIndex++; } objectIdentifierComponents = new int[objectIdentifierComponentsList.size()]; for (int i = 0; i < objectIdentifierComponentsList.size(); i++) { objectIdentifierComponents[i] = objectIdentifierComponentsList.get(i); } return codeLength; } }
BerObjectIdentifier { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val == 0) { objectIdentifierComponents = new int[0]; return codeLength; } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) == -1) { throw new IOException("Error Decoding BerObjectIdentifier"); } codeLength += length.val; List<Integer> objectIdentifierComponentsList = new ArrayList<Integer>(); int subIDEndIndex = 0; while ((byteCode[subIDEndIndex] & 0x80) == 0x80) { if (subIDEndIndex >= (length.val - 1)) { throw new IOException("Invalid Object Identifier"); } subIDEndIndex++; } int subidentifier = 0; for (int i = 0; i <= subIDEndIndex; i++) { subidentifier |= (byteCode[i] << ((subIDEndIndex - i) * 7)); } if (subidentifier < 40) { objectIdentifierComponentsList.add(0); objectIdentifierComponentsList.add(subidentifier); } else if (subidentifier < 80) { objectIdentifierComponentsList.add(1); objectIdentifierComponentsList.add(subidentifier - 40); } else { objectIdentifierComponentsList.add(2); objectIdentifierComponentsList.add(subidentifier - 80); } subIDEndIndex++; while (subIDEndIndex < length.val) { int subIDStartIndex = subIDEndIndex; while ((byteCode[subIDEndIndex] & 0x80) == 0x80) { if (subIDEndIndex == (length.val - 1)) { throw new IOException("Invalid Object Identifier"); } subIDEndIndex++; } subidentifier = 0; for (int j = subIDStartIndex; j <= subIDEndIndex; j++) { subidentifier |= ((byteCode[j] & 0x7f) << ((subIDEndIndex - j) * 7)); } objectIdentifierComponentsList.add(subidentifier); subIDEndIndex++; } objectIdentifierComponents = new int[objectIdentifierComponentsList.size()]; for (int i = 0; i < objectIdentifierComponentsList.size(); i++) { objectIdentifierComponents[i] = objectIdentifierComponentsList.get(i); } return codeLength; } BerObjectIdentifier(); BerObjectIdentifier(byte[] code); BerObjectIdentifier(int[] objectIdentifierComponents); }
BerObjectIdentifier { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val == 0) { objectIdentifierComponents = new int[0]; return codeLength; } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) == -1) { throw new IOException("Error Decoding BerObjectIdentifier"); } codeLength += length.val; List<Integer> objectIdentifierComponentsList = new ArrayList<Integer>(); int subIDEndIndex = 0; while ((byteCode[subIDEndIndex] & 0x80) == 0x80) { if (subIDEndIndex >= (length.val - 1)) { throw new IOException("Invalid Object Identifier"); } subIDEndIndex++; } int subidentifier = 0; for (int i = 0; i <= subIDEndIndex; i++) { subidentifier |= (byteCode[i] << ((subIDEndIndex - i) * 7)); } if (subidentifier < 40) { objectIdentifierComponentsList.add(0); objectIdentifierComponentsList.add(subidentifier); } else if (subidentifier < 80) { objectIdentifierComponentsList.add(1); objectIdentifierComponentsList.add(subidentifier - 40); } else { objectIdentifierComponentsList.add(2); objectIdentifierComponentsList.add(subidentifier - 80); } subIDEndIndex++; while (subIDEndIndex < length.val) { int subIDStartIndex = subIDEndIndex; while ((byteCode[subIDEndIndex] & 0x80) == 0x80) { if (subIDEndIndex == (length.val - 1)) { throw new IOException("Invalid Object Identifier"); } subIDEndIndex++; } subidentifier = 0; for (int j = subIDStartIndex; j <= subIDEndIndex; j++) { subidentifier |= ((byteCode[j] & 0x7f) << ((subIDEndIndex - j) * 7)); } objectIdentifierComponentsList.add(subidentifier); subIDEndIndex++; } objectIdentifierComponents = new int[objectIdentifierComponentsList.size()]; for (int i = 0; i < objectIdentifierComponentsList.size(); i++) { objectIdentifierComponents[i] = objectIdentifierComponentsList.get(i); } return codeLength; } BerObjectIdentifier(); BerObjectIdentifier(byte[] code); BerObjectIdentifier(int[] objectIdentifierComponents); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); @Override String toString(); }
BerObjectIdentifier { public int decode(InputStream iStream, boolean explicit) throws IOException { int codeLength = 0; if (explicit) { codeLength += id.decodeAndCheck(iStream); } BerLength length = new BerLength(); codeLength += length.decode(iStream); if (length.val == 0) { objectIdentifierComponents = new int[0]; return codeLength; } byte[] byteCode = new byte[length.val]; if (iStream.read(byteCode, 0, length.val) == -1) { throw new IOException("Error Decoding BerObjectIdentifier"); } codeLength += length.val; List<Integer> objectIdentifierComponentsList = new ArrayList<Integer>(); int subIDEndIndex = 0; while ((byteCode[subIDEndIndex] & 0x80) == 0x80) { if (subIDEndIndex >= (length.val - 1)) { throw new IOException("Invalid Object Identifier"); } subIDEndIndex++; } int subidentifier = 0; for (int i = 0; i <= subIDEndIndex; i++) { subidentifier |= (byteCode[i] << ((subIDEndIndex - i) * 7)); } if (subidentifier < 40) { objectIdentifierComponentsList.add(0); objectIdentifierComponentsList.add(subidentifier); } else if (subidentifier < 80) { objectIdentifierComponentsList.add(1); objectIdentifierComponentsList.add(subidentifier - 40); } else { objectIdentifierComponentsList.add(2); objectIdentifierComponentsList.add(subidentifier - 80); } subIDEndIndex++; while (subIDEndIndex < length.val) { int subIDStartIndex = subIDEndIndex; while ((byteCode[subIDEndIndex] & 0x80) == 0x80) { if (subIDEndIndex == (length.val - 1)) { throw new IOException("Invalid Object Identifier"); } subIDEndIndex++; } subidentifier = 0; for (int j = subIDStartIndex; j <= subIDEndIndex; j++) { subidentifier |= ((byteCode[j] & 0x7f) << ((subIDEndIndex - j) * 7)); } objectIdentifierComponentsList.add(subidentifier); subIDEndIndex++; } objectIdentifierComponents = new int[objectIdentifierComponentsList.size()]; for (int i = 0; i < objectIdentifierComponentsList.size(); i++) { objectIdentifierComponents[i] = objectIdentifierComponentsList.get(i); } return codeLength; } BerObjectIdentifier(); BerObjectIdentifier(byte[] code); BerObjectIdentifier(int[] objectIdentifierComponents); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); @Override String toString(); final static BerIdentifier identifier; public byte[] code; public int[] objectIdentifierComponents; }
@Test public void encodeLength2() throws IOException { BerByteArrayOutputStream berOStream = new BerByteArrayOutputStream(50); int codedLength = BerLength.encodeLength(berOStream, 128); Assert.assertEquals(2, codedLength); byte[] expectedBytes = new byte[] { (byte) 0x81, (byte) 128 }; Assert.assertArrayEquals(expectedBytes, berOStream.getArray()); }
public static int encodeLength(BerByteArrayOutputStream berOStream, int length) throws IOException { if (length <= 127) { berOStream.write((byte) length); return 1; } else { int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { berOStream.write((length >> 8 * i) & 0xff); } berOStream.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } }
BerLength { public static int encodeLength(BerByteArrayOutputStream berOStream, int length) throws IOException { if (length <= 127) { berOStream.write((byte) length); return 1; } else { int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { berOStream.write((length >> 8 * i) & 0xff); } berOStream.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } } }
BerLength { public static int encodeLength(BerByteArrayOutputStream berOStream, int length) throws IOException { if (length <= 127) { berOStream.write((byte) length); return 1; } else { int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { berOStream.write((length >> 8 * i) & 0xff); } berOStream.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } } BerLength(); }
BerLength { public static int encodeLength(BerByteArrayOutputStream berOStream, int length) throws IOException { if (length <= 127) { berOStream.write((byte) length); return 1; } else { int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { berOStream.write((length >> 8 * i) & 0xff); } berOStream.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } } BerLength(); int decode(InputStream iStream); static int encodeLength(BerByteArrayOutputStream berOStream, int length); }
BerLength { public static int encodeLength(BerByteArrayOutputStream berOStream, int length) throws IOException { if (length <= 127) { berOStream.write((byte) length); return 1; } else { int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { berOStream.write((length >> 8 * i) & 0xff); } berOStream.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } } BerLength(); int decode(InputStream iStream); static int encodeLength(BerByteArrayOutputStream berOStream, int length); public int val; }
@Test public void explicitDecoding() throws IOException { byte[] byteCode = new byte[] { (byte) 0x81, (byte) 128 }; ByteArrayInputStream berInputStream = new ByteArrayInputStream(byteCode); BerLength berLength = new BerLength(); berLength.decode(berInputStream); Assert.assertEquals(128, berLength.val); }
public int decode(InputStream iStream) throws IOException { val = iStream.read(); int length = 1; if ((val & 0x80) != 0) { int lengthLength = val & 0x7f; if (lengthLength == 0) { val = -1; return 1; } if (lengthLength > 4) { throw new IOException("Length is out of bound!"); } val = 0; byte[] byteCode = new byte[lengthLength]; if (iStream.read(byteCode, 0, lengthLength) == -1) { throw new IOException("Error Decoding ASN1Integer"); } length += lengthLength; for (int i = 0; i < lengthLength; i++) { val |= (byteCode[i] & 0xff) << (8 * (lengthLength - i - 1)); } } return length; }
BerLength { public int decode(InputStream iStream) throws IOException { val = iStream.read(); int length = 1; if ((val & 0x80) != 0) { int lengthLength = val & 0x7f; if (lengthLength == 0) { val = -1; return 1; } if (lengthLength > 4) { throw new IOException("Length is out of bound!"); } val = 0; byte[] byteCode = new byte[lengthLength]; if (iStream.read(byteCode, 0, lengthLength) == -1) { throw new IOException("Error Decoding ASN1Integer"); } length += lengthLength; for (int i = 0; i < lengthLength; i++) { val |= (byteCode[i] & 0xff) << (8 * (lengthLength - i - 1)); } } return length; } }
BerLength { public int decode(InputStream iStream) throws IOException { val = iStream.read(); int length = 1; if ((val & 0x80) != 0) { int lengthLength = val & 0x7f; if (lengthLength == 0) { val = -1; return 1; } if (lengthLength > 4) { throw new IOException("Length is out of bound!"); } val = 0; byte[] byteCode = new byte[lengthLength]; if (iStream.read(byteCode, 0, lengthLength) == -1) { throw new IOException("Error Decoding ASN1Integer"); } length += lengthLength; for (int i = 0; i < lengthLength; i++) { val |= (byteCode[i] & 0xff) << (8 * (lengthLength - i - 1)); } } return length; } BerLength(); }
BerLength { public int decode(InputStream iStream) throws IOException { val = iStream.read(); int length = 1; if ((val & 0x80) != 0) { int lengthLength = val & 0x7f; if (lengthLength == 0) { val = -1; return 1; } if (lengthLength > 4) { throw new IOException("Length is out of bound!"); } val = 0; byte[] byteCode = new byte[lengthLength]; if (iStream.read(byteCode, 0, lengthLength) == -1) { throw new IOException("Error Decoding ASN1Integer"); } length += lengthLength; for (int i = 0; i < lengthLength; i++) { val |= (byteCode[i] & 0xff) << (8 * (lengthLength - i - 1)); } } return length; } BerLength(); int decode(InputStream iStream); static int encodeLength(BerByteArrayOutputStream berOStream, int length); }
BerLength { public int decode(InputStream iStream) throws IOException { val = iStream.read(); int length = 1; if ((val & 0x80) != 0) { int lengthLength = val & 0x7f; if (lengthLength == 0) { val = -1; return 1; } if (lengthLength > 4) { throw new IOException("Length is out of bound!"); } val = 0; byte[] byteCode = new byte[lengthLength]; if (iStream.read(byteCode, 0, lengthLength) == -1) { throw new IOException("Error Decoding ASN1Integer"); } length += lengthLength; for (int i = 0; i < lengthLength; i++) { val |= (byteCode[i] & 0xff) << (8 * (lengthLength - i - 1)); } } return length; } BerLength(); int decode(InputStream iStream); static int encodeLength(BerByteArrayOutputStream berOStream, int length); public int val; }
@Test public void implicitEncoding1() throws IOException { BerByteArrayOutputStream berBAOStream = new BerByteArrayOutputStream(50); IntegerUnivPrim testInteger = new IntegerUnivPrim(51); int length = testInteger.encode(berBAOStream, false); Assert.assertEquals(2, length); byte[] expectedBytes = new byte[] { 0x01, 0x33 }; Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); final static BerIdentifier identifier; public BerIdentifier id; public byte[] code; public long val; }
@Test public void implicitEncoding2() throws IOException { BerByteArrayOutputStream berBAOStream = new BerByteArrayOutputStream(50); IntegerUnivPrim testInteger = new IntegerUnivPrim(256); int length = testInteger.encode(berBAOStream, false); Assert.assertEquals(3, length); byte[] expectedBytes = new byte[] { 0x02, 0x01, 0x00 }; Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); final static BerIdentifier identifier; public BerIdentifier id; public byte[] code; public long val; }
@Test public void implicitEncoding3() throws IOException { BerByteArrayOutputStream berBAOStream = new BerByteArrayOutputStream(50); IntegerUnivPrim testInteger = new IntegerUnivPrim(0); int length = testInteger.encode(berBAOStream, false); Assert.assertEquals(2, length); byte[] expectedBytes = new byte[] { 0x01, 0x00 }; Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); final static BerIdentifier identifier; public BerIdentifier id; public byte[] code; public long val; }
@Test public void implicitEncoding4() throws IOException { BerByteArrayOutputStream berBAOStream = new BerByteArrayOutputStream(50); IntegerUnivPrim testInteger = new IntegerUnivPrim(127); int length = testInteger.encode(berBAOStream, false); Assert.assertEquals(2, length); byte[] expectedBytes = new byte[] { 0x01, 0x7f }; Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); final static BerIdentifier identifier; public BerIdentifier id; public byte[] code; public long val; }
@Test public void implicitEncoding5() throws IOException { BerByteArrayOutputStream berBAOStream = new BerByteArrayOutputStream(50); IntegerUnivPrim testInteger = new IntegerUnivPrim(128); int length = testInteger.encode(berBAOStream, false); Assert.assertEquals(3, length); byte[] expectedBytes = new byte[] { 0x02, 0x00, (byte) 0x80 }; Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); final static BerIdentifier identifier; public BerIdentifier id; public byte[] code; public long val; }
@Test public void implicitEncoding6() throws IOException { BerByteArrayOutputStream berBAOStream = new BerByteArrayOutputStream(50); IntegerUnivPrim testInteger = new IntegerUnivPrim(-128); int length = testInteger.encode(berBAOStream, false); Assert.assertEquals(2, length); byte[] expectedBytes = new byte[] { 0x01, (byte) 0x80 }; Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); }
BerInteger { public int encode(BerByteArrayOutputStream berOStream, boolean explicit) throws IOException { int codeLength; if (code != null) { codeLength = code.length; for (int i = code.length - 1; i >= 0; i--) { berOStream.write(code[i]); } } else { codeLength = 1; while (val > (Math.pow(2, (8 * codeLength) - 1) - 1) || val < Math.pow(-2, (8 * codeLength) - 1) && codeLength < 8) { codeLength++; } for (int i = 0; i < codeLength; i++) { berOStream.write((int) (val >> 8 * (i))); } codeLength += BerLength.encodeLength(berOStream, codeLength); } if (explicit) { codeLength += id.encode(berOStream); } return codeLength; } BerInteger(); BerInteger(byte[] code); BerInteger(long val); int encode(BerByteArrayOutputStream berOStream, boolean explicit); int decode(InputStream iStream, boolean explicit); void encodeAndSave(int encodingSizeGuess); final static BerIdentifier identifier; public BerIdentifier id; public byte[] code; public long val; }
@Test public void testMyFilter() { List<Integer> numbers = Arrays.asList(4, 5, 7, 8, 10, 11, 14, 15); List<Integer> result = Functions.myFilter(numbers, item -> item % 2 == 0); assertEquals(Arrays.asList(4, 8, 10, 14), result); }
public static <T> List<T> myFilter(List<T> list, MyPredicate<T> myPredicate) { ArrayList<T> result = new ArrayList<>(); for (T t : list) { if (myPredicate.test(t)) result.add(t); } return result; }
Functions { public static <T> List<T> myFilter(List<T> list, MyPredicate<T> myPredicate) { ArrayList<T> result = new ArrayList<>(); for (T t : list) { if (myPredicate.test(t)) result.add(t); } return result; } }
Functions { public static <T> List<T> myFilter(List<T> list, MyPredicate<T> myPredicate) { ArrayList<T> result = new ArrayList<>(); for (T t : list) { if (myPredicate.test(t)) result.add(t); } return result; } }
Functions { public static <T> List<T> myFilter(List<T> list, MyPredicate<T> myPredicate) { ArrayList<T> result = new ArrayList<>(); for (T t : list) { if (myPredicate.test(t)) result.add(t); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
Functions { public static <T> List<T> myFilter(List<T> list, MyPredicate<T> myPredicate) { ArrayList<T> result = new ArrayList<>(); for (T t : list) { if (myPredicate.test(t)) result.add(t); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
@Test public void testMyGenerate() { List<LocalDateTime> localDateTimes = Functions.myGenerate(() -> { try { Thread.sleep(1000); } catch (InterruptedException e) { } return LocalDateTime.now(); }, 10); System.out.println(localDateTimes); }
public static <T> List<T> myGenerate(MySupplier<T> supplier, int count) { List<T> result = new ArrayList<>(); for (int i = 0; i < count; i++) { result.add(supplier.get()); } return result; }
Functions { public static <T> List<T> myGenerate(MySupplier<T> supplier, int count) { List<T> result = new ArrayList<>(); for (int i = 0; i < count; i++) { result.add(supplier.get()); } return result; } }
Functions { public static <T> List<T> myGenerate(MySupplier<T> supplier, int count) { List<T> result = new ArrayList<>(); for (int i = 0; i < count; i++) { result.add(supplier.get()); } return result; } }
Functions { public static <T> List<T> myGenerate(MySupplier<T> supplier, int count) { List<T> result = new ArrayList<>(); for (int i = 0; i < count; i++) { result.add(supplier.get()); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
Functions { public static <T> List<T> myGenerate(MySupplier<T> supplier, int count) { List<T> result = new ArrayList<>(); for (int i = 0; i < count; i++) { result.add(supplier.get()); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
@Test public void testClosuresAvoidRepeats() { List<String> names = Arrays.asList("Foo", "Ramen", "Naan", "Ravioli"); System.out.println(Functions.myFilter(names, stringHasSizeOf(4))); System.out.println(Functions.myFilter(names, stringHasSizeOf(2))); }
public static <T> List<T> myFilter(List<T> list, MyPredicate<T> myPredicate) { ArrayList<T> result = new ArrayList<>(); for (T t : list) { if (myPredicate.test(t)) result.add(t); } return result; }
Functions { public static <T> List<T> myFilter(List<T> list, MyPredicate<T> myPredicate) { ArrayList<T> result = new ArrayList<>(); for (T t : list) { if (myPredicate.test(t)) result.add(t); } return result; } }
Functions { public static <T> List<T> myFilter(List<T> list, MyPredicate<T> myPredicate) { ArrayList<T> result = new ArrayList<>(); for (T t : list) { if (myPredicate.test(t)) result.add(t); } return result; } }
Functions { public static <T> List<T> myFilter(List<T> list, MyPredicate<T> myPredicate) { ArrayList<T> result = new ArrayList<>(); for (T t : list) { if (myPredicate.test(t)) result.add(t); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
Functions { public static <T> List<T> myFilter(List<T> list, MyPredicate<T> myPredicate) { ArrayList<T> result = new ArrayList<>(); for (T t : list) { if (myPredicate.test(t)) result.add(t); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
@Test public void testMyMap() { List<Integer> numbers = Arrays.asList(4, 5, 7, 8); List<Integer> mapped = Functions.myMap(numbers, t -> t + 2); assertEquals(Arrays.asList(6, 7, 9, 10), mapped); }
public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
@Test public void testMyFlatMap() { List<Integer> numbers = Arrays.asList(4, 5, 7, 8); List<Integer> mapped = Functions.myFlatMap(numbers, t -> List.of(t - 1, t, t + 1)); assertEquals(Arrays.asList(3, 4, 5, 4, 5, 6, 6, 7, 8, 7, 8, 9), mapped); }
public static <T, R> List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { List<R> application = myFunction.apply(t); result.addAll(application); } return result; }
Functions { public static <T, R> List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { List<R> application = myFunction.apply(t); result.addAll(application); } return result; } }
Functions { public static <T, R> List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { List<R> application = myFunction.apply(t); result.addAll(application); } return result; } }
Functions { public static <T, R> List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { List<R> application = myFunction.apply(t); result.addAll(application); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
Functions { public static <T, R> List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { List<R> application = myFunction.apply(t); result.addAll(application); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
@Test public void testMyForEach() { List<Integer> numbers = Arrays.asList(4, 5, 7, 8); Functions.myForEach(numbers, new MyConsumer<Integer>() { @Override public void accept(Integer x) { System.out.println(x); } }); }
public static <T> void myForEach(List<T> list, MyConsumer<T> myConsumer) { for (T t : list) { myConsumer.accept(t); } }
Functions { public static <T> void myForEach(List<T> list, MyConsumer<T> myConsumer) { for (T t : list) { myConsumer.accept(t); } } }
Functions { public static <T> void myForEach(List<T> list, MyConsumer<T> myConsumer) { for (T t : list) { myConsumer.accept(t); } } }
Functions { public static <T> void myForEach(List<T> list, MyConsumer<T> myConsumer) { for (T t : list) { myConsumer.accept(t); } } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
Functions { public static <T> void myForEach(List<T> list, MyConsumer<T> myConsumer) { for (T t : list) { myConsumer.accept(t); } } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
@Test public void testMethodReferenceAStaticMethod() { List<Integer> numbers = Arrays.asList(2, 4, 5, 1, 9, 15, 19, 21, 33, 78, 93, 10); System.out.println(Functions.myMap(numbers, Math::abs)); }
public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
@Test public void testMethodReferenceAContainingType() { List<String> words = Arrays.asList("One", "Two", "Three", "Four"); List<Integer> result = Functions.myMap(words, String::length); System.out.println(result); }
public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
@Test public void testMethodReferenceAContainingTypeTrickQuestion() { List<Integer> numbers = Arrays.asList(2, 4, 5, 1, 9, 15, 19, 21, 33, 78, 93, 10); System.out.println(Functions.myMap(numbers, Object::toString)); }
public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
@Test public void testTwoOrMoreItemsInALambda() { List<Integer> numbers = Arrays.asList(2, 4, 5, 1, 9, 15, 19, 21, 33, 78, 93, 10); System.out.println(Functions.myMap(numbers, x -> { int y = 100; int z = 10; return y + z + x; })); }
public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
@Test public void testMethodReferenceAnInstance() { List<Integer> numbers = Arrays.asList(2, 4, 5, 1, 9, 15, 19, 21, 33, 78, 93, 10); TaxRate taxRate2016 = new TaxRate(2016, .085); System.out.println(Functions.myMap(numbers, taxRate2016::apply)); }
public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
@Test public void testMethodReferenceANewType() { List<Integer> numbers = Arrays.asList(2, 4, 5, 1, 9, 15, 19, 21, 33, 78, 93, 10); System.out.println(Functions.myMap(numbers, Double::new)); }
public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
Functions { public static <T, R> List<R> myMap(List<T> list, MyFunction<T, R> myFunction) { ArrayList<R> result = new ArrayList<>(); for (T t : list) { result.add(myFunction.apply(t)); } return result; } static List<T> myFilter(List<T> list, MyPredicate<T> myPredicate); static List<R> myMap(List<T> list, MyFunction<T, R> myFunction); static List<R> myFlatMap(List<T> list, MyFunction<T, List<R>> myFunction); static void myForEach(List<T> list, MyConsumer<T> myConsumer); static List<T> myGenerate(MySupplier<T> supplier, int count); }
@Test public void joinPath() { assertEquals("http: assertEquals("http: assertEquals("http: assertEquals("http: assertEquals("http: assertEquals("http: }
public static String joinPath(final String firstPath, final String secondPath) { Validate.notEmpty(firstPath); Validate.notEmpty(secondPath); final String tmp1 = firstPath.endsWith("/") ? firstPath.substring(0, firstPath.length() - 1) : firstPath; final String tmp2 = secondPath.startsWith("/") ? (tmp1 + secondPath) : (tmp1 + "/" + secondPath); return tmp2.endsWith("/") ? tmp2.substring(0, tmp2.length() - 1) : tmp2; }
WeChatUtils { public static String joinPath(final String firstPath, final String secondPath) { Validate.notEmpty(firstPath); Validate.notEmpty(secondPath); final String tmp1 = firstPath.endsWith("/") ? firstPath.substring(0, firstPath.length() - 1) : firstPath; final String tmp2 = secondPath.startsWith("/") ? (tmp1 + secondPath) : (tmp1 + "/" + secondPath); return tmp2.endsWith("/") ? tmp2.substring(0, tmp2.length() - 1) : tmp2; } }
WeChatUtils { public static String joinPath(final String firstPath, final String secondPath) { Validate.notEmpty(firstPath); Validate.notEmpty(secondPath); final String tmp1 = firstPath.endsWith("/") ? firstPath.substring(0, firstPath.length() - 1) : firstPath; final String tmp2 = secondPath.startsWith("/") ? (tmp1 + secondPath) : (tmp1 + "/" + secondPath); return tmp2.endsWith("/") ? tmp2.substring(0, tmp2.length() - 1) : tmp2; } private WeChatUtils(); }
WeChatUtils { public static String joinPath(final String firstPath, final String secondPath) { Validate.notEmpty(firstPath); Validate.notEmpty(secondPath); final String tmp1 = firstPath.endsWith("/") ? firstPath.substring(0, firstPath.length() - 1) : firstPath; final String tmp2 = secondPath.startsWith("/") ? (tmp1 + secondPath) : (tmp1 + "/" + secondPath); return tmp2.endsWith("/") ? tmp2.substring(0, tmp2.length() - 1) : tmp2; } private WeChatUtils(); @NotNull static String uuid32(); static String joinPath(final String firstPath, final String secondPath); static String urlEncode(final String urlStr); }
WeChatUtils { public static String joinPath(final String firstPath, final String secondPath) { Validate.notEmpty(firstPath); Validate.notEmpty(secondPath); final String tmp1 = firstPath.endsWith("/") ? firstPath.substring(0, firstPath.length() - 1) : firstPath; final String tmp2 = secondPath.startsWith("/") ? (tmp1 + secondPath) : (tmp1 + "/" + secondPath); return tmp2.endsWith("/") ? tmp2.substring(0, tmp2.length() - 1) : tmp2; } private WeChatUtils(); @NotNull static String uuid32(); static String joinPath(final String firstPath, final String secondPath); static String urlEncode(final String urlStr); }
@Test public void unifiedOrder() { stubFor(post(urlEqualTo(WeChatPayClient.UNIFIED_ORDER_PATH)) .willReturn(aResponse() .withStatus(200) .withHeader("Content-Type", MediaType.APPLICATION_XML_VALUE) .withBody("<xml><return_code>SUCCESS</return_code><result_code>SUCCESS</result_code></xml>"))); WeChatPayConfigurator.DEFAULT.setMchKey("key"); final UnifiedOrderRequest request = UnifiedOrderRequest.createWithNative("body", "outTradeNo", 100); final UnifiedOrderResponse unifiedOrderResponse = this.weChatPayClient.unifiedOrder(request); assertThat(unifiedOrderResponse) .hasReturnCode("SUCCESS") .hasResultCode("SUCCESS"); }
@Override public UnifiedOrderResponse unifiedOrder( final UnifiedOrderRequest request) throws WeChatPayException { Objects.requireNonNull(request); return postForEntity( WeChatPayClient.UNIFIED_ORDER_PATH, request, UnifiedOrderResponse.class) .getBody(); }
WeChatPayRestTemplateClient implements WeChatPayClient { @Override public UnifiedOrderResponse unifiedOrder( final UnifiedOrderRequest request) throws WeChatPayException { Objects.requireNonNull(request); return postForEntity( WeChatPayClient.UNIFIED_ORDER_PATH, request, UnifiedOrderResponse.class) .getBody(); } }
WeChatPayRestTemplateClient implements WeChatPayClient { @Override public UnifiedOrderResponse unifiedOrder( final UnifiedOrderRequest request) throws WeChatPayException { Objects.requireNonNull(request); return postForEntity( WeChatPayClient.UNIFIED_ORDER_PATH, request, UnifiedOrderResponse.class) .getBody(); } WeChatPayRestTemplateClient( final RestTemplate restTemplate, final WeChatPayProperties weChatPayProperties); }
WeChatPayRestTemplateClient implements WeChatPayClient { @Override public UnifiedOrderResponse unifiedOrder( final UnifiedOrderRequest request) throws WeChatPayException { Objects.requireNonNull(request); return postForEntity( WeChatPayClient.UNIFIED_ORDER_PATH, request, UnifiedOrderResponse.class) .getBody(); } WeChatPayRestTemplateClient( final RestTemplate restTemplate, final WeChatPayProperties weChatPayProperties); @Override UnifiedOrderResponse unifiedOrder( final UnifiedOrderRequest request); @Override OrderQueryResponse orderQuery( final OrderQueryRequest request); @Override CloseOrderResponse closeOrder( final CloseOrderRequest request); @Override RefundResponse refund( final RefundRequest request); @Override RefundQueryResponse refundQuery( final RefundQueryRequest request); }
WeChatPayRestTemplateClient implements WeChatPayClient { @Override public UnifiedOrderResponse unifiedOrder( final UnifiedOrderRequest request) throws WeChatPayException { Objects.requireNonNull(request); return postForEntity( WeChatPayClient.UNIFIED_ORDER_PATH, request, UnifiedOrderResponse.class) .getBody(); } WeChatPayRestTemplateClient( final RestTemplate restTemplate, final WeChatPayProperties weChatPayProperties); @Override UnifiedOrderResponse unifiedOrder( final UnifiedOrderRequest request); @Override OrderQueryResponse orderQuery( final OrderQueryRequest request); @Override CloseOrderResponse closeOrder( final CloseOrderRequest request); @Override RefundResponse refund( final RefundRequest request); @Override RefundQueryResponse refundQuery( final RefundQueryRequest request); }
@Test public void orderQuery() { }
@Override public OrderQueryResponse orderQuery( final OrderQueryRequest request) throws WeChatPayException { Objects.requireNonNull(request); return postForEntity( WeChatPayClient.ORDER_QUERY_PATH, request, OrderQueryResponse.class) .getBody(); }
WeChatPayRestTemplateClient implements WeChatPayClient { @Override public OrderQueryResponse orderQuery( final OrderQueryRequest request) throws WeChatPayException { Objects.requireNonNull(request); return postForEntity( WeChatPayClient.ORDER_QUERY_PATH, request, OrderQueryResponse.class) .getBody(); } }
WeChatPayRestTemplateClient implements WeChatPayClient { @Override public OrderQueryResponse orderQuery( final OrderQueryRequest request) throws WeChatPayException { Objects.requireNonNull(request); return postForEntity( WeChatPayClient.ORDER_QUERY_PATH, request, OrderQueryResponse.class) .getBody(); } WeChatPayRestTemplateClient( final RestTemplate restTemplate, final WeChatPayProperties weChatPayProperties); }
WeChatPayRestTemplateClient implements WeChatPayClient { @Override public OrderQueryResponse orderQuery( final OrderQueryRequest request) throws WeChatPayException { Objects.requireNonNull(request); return postForEntity( WeChatPayClient.ORDER_QUERY_PATH, request, OrderQueryResponse.class) .getBody(); } WeChatPayRestTemplateClient( final RestTemplate restTemplate, final WeChatPayProperties weChatPayProperties); @Override UnifiedOrderResponse unifiedOrder( final UnifiedOrderRequest request); @Override OrderQueryResponse orderQuery( final OrderQueryRequest request); @Override CloseOrderResponse closeOrder( final CloseOrderRequest request); @Override RefundResponse refund( final RefundRequest request); @Override RefundQueryResponse refundQuery( final RefundQueryRequest request); }
WeChatPayRestTemplateClient implements WeChatPayClient { @Override public OrderQueryResponse orderQuery( final OrderQueryRequest request) throws WeChatPayException { Objects.requireNonNull(request); return postForEntity( WeChatPayClient.ORDER_QUERY_PATH, request, OrderQueryResponse.class) .getBody(); } WeChatPayRestTemplateClient( final RestTemplate restTemplate, final WeChatPayProperties weChatPayProperties); @Override UnifiedOrderResponse unifiedOrder( final UnifiedOrderRequest request); @Override OrderQueryResponse orderQuery( final OrderQueryRequest request); @Override CloseOrderResponse closeOrder( final CloseOrderRequest request); @Override RefundResponse refund( final RefundRequest request); @Override RefundQueryResponse refundQuery( final RefundQueryRequest request); }
@Test public void authorizeCode() throws Exception { final WeChatMpAccessTokenResponse accessTokenResponse = new WeChatMpAccessTokenResponse(); accessTokenResponse.setErrCode("0"); given(this.weChatMpClient.accessToken("code")).willReturn(accessTokenResponse); this.mvc.perform(get(WeChatMpProperties.AUTHORIZE_CODE_PATH) .param("code", "code") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); }
@GetMapping(path = "${wechat.mp.authorize-code-path:" + WeChatMpProperties.AUTHORIZE_CODE_PATH + '}') public void authorizeCode( @RequestParam("code") final String code) { final WeChatMpAccessTokenResponse accessTokenResponse = this.weChatMpClient.accessToken(code); if (accessTokenResponse.isSuccessful()) { this.publisher.publishEvent(new WeChatMpAuthenticationSuccessEvent(accessTokenResponse)); } else { throw new WeChatMpAuthenticationException(String.format("errcode: %s, errmsg: %s", accessTokenResponse.getErrCode(), accessTokenResponse.getErrMsg())); } }
WeChatMpController { @GetMapping(path = "${wechat.mp.authorize-code-path:" + WeChatMpProperties.AUTHORIZE_CODE_PATH + '}') public void authorizeCode( @RequestParam("code") final String code) { final WeChatMpAccessTokenResponse accessTokenResponse = this.weChatMpClient.accessToken(code); if (accessTokenResponse.isSuccessful()) { this.publisher.publishEvent(new WeChatMpAuthenticationSuccessEvent(accessTokenResponse)); } else { throw new WeChatMpAuthenticationException(String.format("errcode: %s, errmsg: %s", accessTokenResponse.getErrCode(), accessTokenResponse.getErrMsg())); } } }
WeChatMpController { @GetMapping(path = "${wechat.mp.authorize-code-path:" + WeChatMpProperties.AUTHORIZE_CODE_PATH + '}') public void authorizeCode( @RequestParam("code") final String code) { final WeChatMpAccessTokenResponse accessTokenResponse = this.weChatMpClient.accessToken(code); if (accessTokenResponse.isSuccessful()) { this.publisher.publishEvent(new WeChatMpAuthenticationSuccessEvent(accessTokenResponse)); } else { throw new WeChatMpAuthenticationException(String.format("errcode: %s, errmsg: %s", accessTokenResponse.getErrCode(), accessTokenResponse.getErrMsg())); } } WeChatMpController( @NotNull final WeChatMpProperties weChatMpProperties, @NotNull final WeChatMpClient weChatMpClient, @NotNull final ApplicationEventPublisher publisher); }
WeChatMpController { @GetMapping(path = "${wechat.mp.authorize-code-path:" + WeChatMpProperties.AUTHORIZE_CODE_PATH + '}') public void authorizeCode( @RequestParam("code") final String code) { final WeChatMpAccessTokenResponse accessTokenResponse = this.weChatMpClient.accessToken(code); if (accessTokenResponse.isSuccessful()) { this.publisher.publishEvent(new WeChatMpAuthenticationSuccessEvent(accessTokenResponse)); } else { throw new WeChatMpAuthenticationException(String.format("errcode: %s, errmsg: %s", accessTokenResponse.getErrCode(), accessTokenResponse.getErrMsg())); } } WeChatMpController( @NotNull final WeChatMpProperties weChatMpProperties, @NotNull final WeChatMpClient weChatMpClient, @NotNull final ApplicationEventPublisher publisher); @GetMapping(path = "${wechat.mp.authorize-path:" + WeChatMpProperties.AUTHORIZE_PATH + "}") RedirectView authorize(@RequestParam("redirect") final String redirect); @GetMapping(path = "${wechat.mp.authorize-code-path:" + WeChatMpProperties.AUTHORIZE_CODE_PATH + '}') void authorizeCode( @RequestParam("code") final String code); }
WeChatMpController { @GetMapping(path = "${wechat.mp.authorize-code-path:" + WeChatMpProperties.AUTHORIZE_CODE_PATH + '}') public void authorizeCode( @RequestParam("code") final String code) { final WeChatMpAccessTokenResponse accessTokenResponse = this.weChatMpClient.accessToken(code); if (accessTokenResponse.isSuccessful()) { this.publisher.publishEvent(new WeChatMpAuthenticationSuccessEvent(accessTokenResponse)); } else { throw new WeChatMpAuthenticationException(String.format("errcode: %s, errmsg: %s", accessTokenResponse.getErrCode(), accessTokenResponse.getErrMsg())); } } WeChatMpController( @NotNull final WeChatMpProperties weChatMpProperties, @NotNull final WeChatMpClient weChatMpClient, @NotNull final ApplicationEventPublisher publisher); @GetMapping(path = "${wechat.mp.authorize-path:" + WeChatMpProperties.AUTHORIZE_PATH + "}") RedirectView authorize(@RequestParam("redirect") final String redirect); @GetMapping(path = "${wechat.mp.authorize-code-path:" + WeChatMpProperties.AUTHORIZE_CODE_PATH + '}') void authorizeCode( @RequestParam("code") final String code); }
@Test public void weChatMpController() throws Exception { ClassPool.getDefault().makeClass("cn.javaer.wechat.spring.boot.starter.mp.ConditionalOnClassTrigger").toClass(); try (AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext()) { context.register(WeChatMpAutoConfiguration.class); context.refresh(); context.getBean(WeChatMpController.class); } }
@Bean @ConditionalOnMissingBean public WeChatMpController weChatMpController(final WeChatMpClient weChatMpClient, final ApplicationEventPublisher publisher) { return new WeChatMpController(this.weChatMpProperties, weChatMpClient, publisher); }
WeChatMpAutoConfiguration { @Bean @ConditionalOnMissingBean public WeChatMpController weChatMpController(final WeChatMpClient weChatMpClient, final ApplicationEventPublisher publisher) { return new WeChatMpController(this.weChatMpProperties, weChatMpClient, publisher); } }
WeChatMpAutoConfiguration { @Bean @ConditionalOnMissingBean public WeChatMpController weChatMpController(final WeChatMpClient weChatMpClient, final ApplicationEventPublisher publisher) { return new WeChatMpController(this.weChatMpProperties, weChatMpClient, publisher); } WeChatMpAutoConfiguration(final WeChatMpProperties weChatMpProperties); }
WeChatMpAutoConfiguration { @Bean @ConditionalOnMissingBean public WeChatMpController weChatMpController(final WeChatMpClient weChatMpClient, final ApplicationEventPublisher publisher) { return new WeChatMpController(this.weChatMpProperties, weChatMpClient, publisher); } WeChatMpAutoConfiguration(final WeChatMpProperties weChatMpProperties); @Bean @ConditionalOnMissingBean WeChatMpController weChatMpController(final WeChatMpClient weChatMpClient, final ApplicationEventPublisher publisher); @Bean @ConditionalOnMissingBean WeChatMpClient weChatMpClient( @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @Autowired(required = false) final RestTemplateBuilder restTemplateBuilder); }
WeChatMpAutoConfiguration { @Bean @ConditionalOnMissingBean public WeChatMpController weChatMpController(final WeChatMpClient weChatMpClient, final ApplicationEventPublisher publisher) { return new WeChatMpController(this.weChatMpProperties, weChatMpClient, publisher); } WeChatMpAutoConfiguration(final WeChatMpProperties weChatMpProperties); @Bean @ConditionalOnMissingBean WeChatMpController weChatMpController(final WeChatMpClient weChatMpClient, final ApplicationEventPublisher publisher); @Bean @ConditionalOnMissingBean WeChatMpClient weChatMpClient( @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @Autowired(required = false) final RestTemplateBuilder restTemplateBuilder); }
@Test public void sign() { final UnifiedOrderResponse response = new UnifiedOrderResponse(); response.setReturnCode("SUCCESS"); response.setReturnMsg("OK"); response.setAppid("wx2421b1c4370ec43b"); response.setMchId("10000100"); response.setNonceStr("IITRi8Iabbblz1Jc"); response.setResultCode("SUCCESS"); response.setPrepayId("wx201411101639507cbf6ffd8b0779950874"); response.setTradeType("JSAPI"); response.beforeSign(); assertEquals("BC884153761883FE608EA956BD05A6F5", WeChatPayUtils.generateSign(response, "key")); }
@NotNull public static String generateSign( @NotNull final BasePayRequest request, @NotNull final String mchKey) { return generateSign(signParamsFrom(request), mchKey); }
WeChatPayUtils { @NotNull public static String generateSign( @NotNull final BasePayRequest request, @NotNull final String mchKey) { return generateSign(signParamsFrom(request), mchKey); } }
WeChatPayUtils { @NotNull public static String generateSign( @NotNull final BasePayRequest request, @NotNull final String mchKey) { return generateSign(signParamsFrom(request), mchKey); } }
WeChatPayUtils { @NotNull public static String generateSign( @NotNull final BasePayRequest request, @NotNull final String mchKey) { return generateSign(signParamsFrom(request), mchKey); } @NotNull static String generateSign( @NotNull final BasePayRequest request, @NotNull final String mchKey); @NotNull static String generateSign( @NotNull final BasePayResponse response, @NotNull final String mchKey); @NotNull static String generateSign( @NotNull final SortedMap<String, String> params, @NotNull final String mchKey); static void checkSuccessful(@NotNull final BasePayResponse response); static void checkSign(@NotNull final BasePayResponse response, @NotNull final String mchKey); static boolean isSuccessful(@NotNull final BasePayResponse response, @NotNull final String mchKey); static Map<String, T> beansMapFrom( @NotNull final SortedMap<String, String> params, @NotNull final Map<String, BiConsumer<String, T>> mapping, @NotNull final Supplier<T> newT); static List<T> beansFrom( @NotNull final SortedMap<String, String> params, @NotNull final Map<String, BiConsumer<String, T>> mapping, @NotNull final Supplier<T> newT); static List<Coupon> couponsFrom(final SortedMap<String, String> params); }
WeChatPayUtils { @NotNull public static String generateSign( @NotNull final BasePayRequest request, @NotNull final String mchKey) { return generateSign(signParamsFrom(request), mchKey); } @NotNull static String generateSign( @NotNull final BasePayRequest request, @NotNull final String mchKey); @NotNull static String generateSign( @NotNull final BasePayResponse response, @NotNull final String mchKey); @NotNull static String generateSign( @NotNull final SortedMap<String, String> params, @NotNull final String mchKey); static void checkSuccessful(@NotNull final BasePayResponse response); static void checkSign(@NotNull final BasePayResponse response, @NotNull final String mchKey); static boolean isSuccessful(@NotNull final BasePayResponse response, @NotNull final String mchKey); static Map<String, T> beansMapFrom( @NotNull final SortedMap<String, String> params, @NotNull final Map<String, BiConsumer<String, T>> mapping, @NotNull final Supplier<T> newT); static List<T> beansFrom( @NotNull final SortedMap<String, String> params, @NotNull final Map<String, BiConsumer<String, T>> mapping, @NotNull final Supplier<T> newT); static List<Coupon> couponsFrom(final SortedMap<String, String> params); }
@Test public void sign4Cache() throws Exception { final UnifiedOrderResponse response = new UnifiedOrderResponse(); response.setReturnCode("SUCCESS"); response.setReturnMsg("OK"); response.setAppid("wx2421b1c4370ec43b"); response.setMchId("10000100"); response.setNonceStr("IITRi8Iabbblz1Jc"); response.setResultCode("SUCCESS"); response.setPrepayId("wx201411101639507cbf6ffd8b0779950874"); response.setTradeType("JSAPI"); WeChatPayUtils.generateSign(response, "key"); assertEquals("BC884153761883FE608EA956BD05A6F5", WeChatPayUtils.generateSign(response, "key")); final Field field = WeChatPayUtils.class.getDeclaredField("CACHE_FOR_SIGN"); field.setAccessible(true); @SuppressWarnings("unchecked") final Map<Class, List<Field>> cache = (Map<Class, List<Field>>) field.get(null); assertThat(cache).hasSize(1); }
@NotNull public static String generateSign( @NotNull final BasePayRequest request, @NotNull final String mchKey) { return generateSign(signParamsFrom(request), mchKey); }
WeChatPayUtils { @NotNull public static String generateSign( @NotNull final BasePayRequest request, @NotNull final String mchKey) { return generateSign(signParamsFrom(request), mchKey); } }
WeChatPayUtils { @NotNull public static String generateSign( @NotNull final BasePayRequest request, @NotNull final String mchKey) { return generateSign(signParamsFrom(request), mchKey); } }
WeChatPayUtils { @NotNull public static String generateSign( @NotNull final BasePayRequest request, @NotNull final String mchKey) { return generateSign(signParamsFrom(request), mchKey); } @NotNull static String generateSign( @NotNull final BasePayRequest request, @NotNull final String mchKey); @NotNull static String generateSign( @NotNull final BasePayResponse response, @NotNull final String mchKey); @NotNull static String generateSign( @NotNull final SortedMap<String, String> params, @NotNull final String mchKey); static void checkSuccessful(@NotNull final BasePayResponse response); static void checkSign(@NotNull final BasePayResponse response, @NotNull final String mchKey); static boolean isSuccessful(@NotNull final BasePayResponse response, @NotNull final String mchKey); static Map<String, T> beansMapFrom( @NotNull final SortedMap<String, String> params, @NotNull final Map<String, BiConsumer<String, T>> mapping, @NotNull final Supplier<T> newT); static List<T> beansFrom( @NotNull final SortedMap<String, String> params, @NotNull final Map<String, BiConsumer<String, T>> mapping, @NotNull final Supplier<T> newT); static List<Coupon> couponsFrom(final SortedMap<String, String> params); }
WeChatPayUtils { @NotNull public static String generateSign( @NotNull final BasePayRequest request, @NotNull final String mchKey) { return generateSign(signParamsFrom(request), mchKey); } @NotNull static String generateSign( @NotNull final BasePayRequest request, @NotNull final String mchKey); @NotNull static String generateSign( @NotNull final BasePayResponse response, @NotNull final String mchKey); @NotNull static String generateSign( @NotNull final SortedMap<String, String> params, @NotNull final String mchKey); static void checkSuccessful(@NotNull final BasePayResponse response); static void checkSign(@NotNull final BasePayResponse response, @NotNull final String mchKey); static boolean isSuccessful(@NotNull final BasePayResponse response, @NotNull final String mchKey); static Map<String, T> beansMapFrom( @NotNull final SortedMap<String, String> params, @NotNull final Map<String, BiConsumer<String, T>> mapping, @NotNull final Supplier<T> newT); static List<T> beansFrom( @NotNull final SortedMap<String, String> params, @NotNull final Map<String, BiConsumer<String, T>> mapping, @NotNull final Supplier<T> newT); static List<Coupon> couponsFrom(final SortedMap<String, String> params); }
@Test public void beansMapFrom() { final SortedMap<String, String> params = new TreeMap<>(); params.put("coupon_refund_id_0", "BC884153761883FE608EA956BD05A6F5"); params.put("coupon_type_0", "CASH"); params.put("coupon_refund_fee_0", "100"); params.put("coupon_refund_id_1", "16BE80B8FD1044069950ADAEDEB812C5"); params.put("coupon_type_1", "NO_CASH"); params.put("coupon_refund_fee_1", "1"); final Map<String, BiConsumer<String, Coupon>> mapping = new HashMap<>(3); mapping.put("coupon_refund_id_", (val, coupon) -> coupon.setId(val)); mapping.put("coupon_type_", (val, coupon) -> coupon.setType(Coupon.Type.valueOf(val))); mapping.put("coupon_refund_fee_", (val, coupon) -> coupon.setFee(Integer.valueOf(val))); final Map<String, Coupon> couponMap = WeChatPayUtils.beansMapFrom( params, mapping, Coupon::new); assertThat(couponMap) .containsOnlyKeys("0", "1"); assertThat(couponMap.get("0")) .hasId("BC884153761883FE608EA956BD05A6F5") .hasType(Coupon.Type.CASH) .hasFee(100); assertThat(couponMap.get("1")) .hasId("16BE80B8FD1044069950ADAEDEB812C5") .hasType(Coupon.Type.NO_CASH) .hasFee(1); }
public static <T> Map<String, T> beansMapFrom( @NotNull final SortedMap<String, String> params, @NotNull final Map<String, BiConsumer<String, T>> mapping, @NotNull final Supplier<T> newT) { final Map<String, T> rtMap = new HashMap<>(); for (final Map.Entry<String, String> entry : params.entrySet()) { final String key = entry.getKey(); final String value = entry.getValue(); if (null == value || value.isEmpty()) { continue; } for (final Map.Entry<String, BiConsumer<String, T>> mappingEntry : mapping.entrySet()) { final String keyStart = mappingEntry.getKey(); if (key.matches(keyStart + "\\d+")) { final String rtKey = key.substring(keyStart.length()); final T t = rtMap.computeIfAbsent(rtKey, k -> newT.get()); mappingEntry.getValue().accept(value, t); } } } return rtMap; }
WeChatPayUtils { public static <T> Map<String, T> beansMapFrom( @NotNull final SortedMap<String, String> params, @NotNull final Map<String, BiConsumer<String, T>> mapping, @NotNull final Supplier<T> newT) { final Map<String, T> rtMap = new HashMap<>(); for (final Map.Entry<String, String> entry : params.entrySet()) { final String key = entry.getKey(); final String value = entry.getValue(); if (null == value || value.isEmpty()) { continue; } for (final Map.Entry<String, BiConsumer<String, T>> mappingEntry : mapping.entrySet()) { final String keyStart = mappingEntry.getKey(); if (key.matches(keyStart + "\\d+")) { final String rtKey = key.substring(keyStart.length()); final T t = rtMap.computeIfAbsent(rtKey, k -> newT.get()); mappingEntry.getValue().accept(value, t); } } } return rtMap; } }
WeChatPayUtils { public static <T> Map<String, T> beansMapFrom( @NotNull final SortedMap<String, String> params, @NotNull final Map<String, BiConsumer<String, T>> mapping, @NotNull final Supplier<T> newT) { final Map<String, T> rtMap = new HashMap<>(); for (final Map.Entry<String, String> entry : params.entrySet()) { final String key = entry.getKey(); final String value = entry.getValue(); if (null == value || value.isEmpty()) { continue; } for (final Map.Entry<String, BiConsumer<String, T>> mappingEntry : mapping.entrySet()) { final String keyStart = mappingEntry.getKey(); if (key.matches(keyStart + "\\d+")) { final String rtKey = key.substring(keyStart.length()); final T t = rtMap.computeIfAbsent(rtKey, k -> newT.get()); mappingEntry.getValue().accept(value, t); } } } return rtMap; } }
WeChatPayUtils { public static <T> Map<String, T> beansMapFrom( @NotNull final SortedMap<String, String> params, @NotNull final Map<String, BiConsumer<String, T>> mapping, @NotNull final Supplier<T> newT) { final Map<String, T> rtMap = new HashMap<>(); for (final Map.Entry<String, String> entry : params.entrySet()) { final String key = entry.getKey(); final String value = entry.getValue(); if (null == value || value.isEmpty()) { continue; } for (final Map.Entry<String, BiConsumer<String, T>> mappingEntry : mapping.entrySet()) { final String keyStart = mappingEntry.getKey(); if (key.matches(keyStart + "\\d+")) { final String rtKey = key.substring(keyStart.length()); final T t = rtMap.computeIfAbsent(rtKey, k -> newT.get()); mappingEntry.getValue().accept(value, t); } } } return rtMap; } @NotNull static String generateSign( @NotNull final BasePayRequest request, @NotNull final String mchKey); @NotNull static String generateSign( @NotNull final BasePayResponse response, @NotNull final String mchKey); @NotNull static String generateSign( @NotNull final SortedMap<String, String> params, @NotNull final String mchKey); static void checkSuccessful(@NotNull final BasePayResponse response); static void checkSign(@NotNull final BasePayResponse response, @NotNull final String mchKey); static boolean isSuccessful(@NotNull final BasePayResponse response, @NotNull final String mchKey); static Map<String, T> beansMapFrom( @NotNull final SortedMap<String, String> params, @NotNull final Map<String, BiConsumer<String, T>> mapping, @NotNull final Supplier<T> newT); static List<T> beansFrom( @NotNull final SortedMap<String, String> params, @NotNull final Map<String, BiConsumer<String, T>> mapping, @NotNull final Supplier<T> newT); static List<Coupon> couponsFrom(final SortedMap<String, String> params); }
WeChatPayUtils { public static <T> Map<String, T> beansMapFrom( @NotNull final SortedMap<String, String> params, @NotNull final Map<String, BiConsumer<String, T>> mapping, @NotNull final Supplier<T> newT) { final Map<String, T> rtMap = new HashMap<>(); for (final Map.Entry<String, String> entry : params.entrySet()) { final String key = entry.getKey(); final String value = entry.getValue(); if (null == value || value.isEmpty()) { continue; } for (final Map.Entry<String, BiConsumer<String, T>> mappingEntry : mapping.entrySet()) { final String keyStart = mappingEntry.getKey(); if (key.matches(keyStart + "\\d+")) { final String rtKey = key.substring(keyStart.length()); final T t = rtMap.computeIfAbsent(rtKey, k -> newT.get()); mappingEntry.getValue().accept(value, t); } } } return rtMap; } @NotNull static String generateSign( @NotNull final BasePayRequest request, @NotNull final String mchKey); @NotNull static String generateSign( @NotNull final BasePayResponse response, @NotNull final String mchKey); @NotNull static String generateSign( @NotNull final SortedMap<String, String> params, @NotNull final String mchKey); static void checkSuccessful(@NotNull final BasePayResponse response); static void checkSign(@NotNull final BasePayResponse response, @NotNull final String mchKey); static boolean isSuccessful(@NotNull final BasePayResponse response, @NotNull final String mchKey); static Map<String, T> beansMapFrom( @NotNull final SortedMap<String, String> params, @NotNull final Map<String, BiConsumer<String, T>> mapping, @NotNull final Supplier<T> newT); static List<T> beansFrom( @NotNull final SortedMap<String, String> params, @NotNull final Map<String, BiConsumer<String, T>> mapping, @NotNull final Supplier<T> newT); static List<Coupon> couponsFrom(final SortedMap<String, String> params); }
@Test public void testParse() { final String xml = WeChatTestUtils.readClassPathFileToUTFString("/WeChatPayNotifyResult.xml", this.getClass()); final NotifyResult notifyResult = WeChatTestUtils.jaxbUnmarshal(xml, NotifyResult.class); assertThat(notifyResult) .hasAppid("wx2421b1c4370ec43b") .hasAttach("支付测试") .hasBankType("CFT") .hasFeeType("CNY") .hasIsSubscribe("Y") .hasMchId("10000100") .hasNonceStr("5d2b6c2a8db53831f7eda20af46e531c") .hasOpenid("oUpF8uMEb4qRXf22hE3X68TekukE") .hasOutTradeNo("1409811653") .hasResultCode("SUCCESS") .hasReturnCode("SUCCESS") .hasSign("B552ED6B279343CB493C5DD0D78AB241") .hasSubMchId("10000100") .hasTimeEnd("20140903131540") .hasTotalFee(1) .hasCouponFee(10) .hasCouponCount(1) .hasTradeType("JSAPI") .hasTransactionId("1004400740201409030005092168"); notifyResult.beforeSign(); assertThat(notifyResult.getCoupons()) .hasSize(5) .extracting("id", "type", "fee") .containsOnly( tuple("coupon_id_0", Coupon.Type.CASH, 0), tuple("coupon_id_1", Coupon.Type.CASH, 1), tuple("coupon_id_2", Coupon.Type.CASH, 2), tuple("coupon_id_3", Coupon.Type.NO_CASH, 3), tuple("coupon_id_4", Coupon.Type.CASH, 4) ); }
@Override public void beforeSign() { if (null == this.coupons && null != this.otherParams) { this.coupons = WeChatPayUtils.couponsFrom(this.otherParams); } }
NotifyResult extends BasePayResponse { @Override public void beforeSign() { if (null == this.coupons && null != this.otherParams) { this.coupons = WeChatPayUtils.couponsFrom(this.otherParams); } } }
NotifyResult extends BasePayResponse { @Override public void beforeSign() { if (null == this.coupons && null != this.otherParams) { this.coupons = WeChatPayUtils.couponsFrom(this.otherParams); } } }
NotifyResult extends BasePayResponse { @Override public void beforeSign() { if (null == this.coupons && null != this.otherParams) { this.coupons = WeChatPayUtils.couponsFrom(this.otherParams); } } @Override void beforeSign(); }
NotifyResult extends BasePayResponse { @Override public void beforeSign() { if (null == this.coupons && null != this.otherParams) { this.coupons = WeChatPayUtils.couponsFrom(this.otherParams); } } @Override void beforeSign(); }
@Test public void beforeSign() { final String xmlStr = WeChatTestUtils.readClassPathFileToUTFString("/WeChatPayRefundQueryResponse.xml", this.getClass()); final RefundQueryResponse response = WeChatTestUtils.jaxbUnmarshal(xmlStr, RefundQueryResponse.class); assertThat(response) .hasReturnCode("SUCCESS") .hasResultCode("SUCCESS") .hasAppid("appid") .hasMchId("mch_id") .hasNonceStr("4EDCA0A0220F466D95C524FA3FE3C100") .hasTotalRefundCount(36) .hasTransactionId("transaction_id") .hasOutTradeNo("out_trade_no") .hasTotalFee(100) .hasCashFee(90) .hasRefundCount(21); response.beforeSign(); assertThat(response.getOtherParams()) .containsEntry("out_refund_no_0", "out_refund_no_0") .containsEntry("refund_id_0", "refund_id_0") .containsEntry("refund_channel_0", "ORIGINAL") .containsEntry("refund_fee_0", "10") .containsEntry("settlement_refund_fee_0", "8") .containsEntry("coupon_refund_fee_0", "20") .containsEntry("coupon_refund_count_0", "3") .containsEntry("refund_status_0", "SUCCESS") .containsEntry("refund_account_0", "REFUND_SOURCE_RECHARGE_FUNDS") .containsEntry("refund_recv_accout_0", "招商银行信用卡0403") .containsEntry("refund_success_time_0", "2016-07-25 15:26:26") .containsEntry("coupon_refund_id_0_0", "BE2F2D9E4D9848E2963BF39A8DE0A2CD") .containsEntry("coupon_type_0_0", "CASH") .containsEntry("coupon_refund_fee_0_0", "2") .containsEntry("coupon_refund_id_0_1", "2DC61D51BE6C4CEA9FAA7E41893B2D97") .containsEntry("coupon_type_0_1", "CASH") .containsEntry("coupon_refund_fee_0_1", "3") .containsEntry("coupon_refund_id_1_0", "FCBA60A940224716A77D06EF202A57AD") .containsEntry("coupon_type_1_0", "NO_CASH") .containsEntry("coupon_refund_fee_1_0", "5") .containsEntry("coupon_refund_id_1_1", "E9D17A8E767847299B038836A5CE34D9") .containsEntry("coupon_type_1_1", "CASH") .containsEntry("coupon_refund_fee_1_1", "3") ; final String generateSign = WeChatPayUtils.generateSign(response, "key"); assertThat(response).hasSign(generateSign); WeChatPayConfigurator.DEFAULT.setMchKey("key"); response.checkSignAndSuccessful(); }
@Override public void beforeSign() { if (null == this.refunds && null != this.otherParams) { final Map<String, Refund> refundsMap = WeChatPayUtils.beansMapFrom(this.otherParams, createRefundMapping(), Refund::new); initCoupons(refundsMap); this.refunds = new ArrayList<>(refundsMap.values()); } }
RefundQueryResponse extends BasePayResponse { @Override public void beforeSign() { if (null == this.refunds && null != this.otherParams) { final Map<String, Refund> refundsMap = WeChatPayUtils.beansMapFrom(this.otherParams, createRefundMapping(), Refund::new); initCoupons(refundsMap); this.refunds = new ArrayList<>(refundsMap.values()); } } }
RefundQueryResponse extends BasePayResponse { @Override public void beforeSign() { if (null == this.refunds && null != this.otherParams) { final Map<String, Refund> refundsMap = WeChatPayUtils.beansMapFrom(this.otherParams, createRefundMapping(), Refund::new); initCoupons(refundsMap); this.refunds = new ArrayList<>(refundsMap.values()); } } }
RefundQueryResponse extends BasePayResponse { @Override public void beforeSign() { if (null == this.refunds && null != this.otherParams) { final Map<String, Refund> refundsMap = WeChatPayUtils.beansMapFrom(this.otherParams, createRefundMapping(), Refund::new); initCoupons(refundsMap); this.refunds = new ArrayList<>(refundsMap.values()); } } @Override void beforeSign(); }
RefundQueryResponse extends BasePayResponse { @Override public void beforeSign() { if (null == this.refunds && null != this.otherParams) { final Map<String, Refund> refundsMap = WeChatPayUtils.beansMapFrom(this.otherParams, createRefundMapping(), Refund::new); initCoupons(refundsMap); this.refunds = new ArrayList<>(refundsMap.values()); } } @Override void beforeSign(); }
@Test public void setOtherProperties() throws Exception { final ObjectMapper mapper = new ObjectMapper(); final Demo demo = mapper.readValue("{\"errcode\":\"d1\",\"any1\":\"any1\",\"any2\":\"any2\"}", Demo.class); Assert.assertEquals("d1", demo.getErrCode()); Assert.assertEquals("any1", demo.getOtherProperties().get("any1")); Assert.assertEquals("any2", demo.getOtherProperties().get("any2")); }
@JsonAnySetter protected void setOtherProperties(final String name, final String value) { this.otherProperties.put(name, value); }
WeChatMpResponse { @JsonAnySetter protected void setOtherProperties(final String name, final String value) { this.otherProperties.put(name, value); } }
WeChatMpResponse { @JsonAnySetter protected void setOtherProperties(final String name, final String value) { this.otherProperties.put(name, value); } }
WeChatMpResponse { @JsonAnySetter protected void setOtherProperties(final String name, final String value) { this.otherProperties.put(name, value); } boolean isSuccessful(); }
WeChatMpResponse { @JsonAnySetter protected void setOtherProperties(final String name, final String value) { this.otherProperties.put(name, value); } boolean isSuccessful(); }
@Test public void generateAuthorizeUrl() { final String authorizeUrl = WeChatMpUtils.generateAuthorizeUrl( "wx520c15f417810387", "https: AuthorizeScope.BASE, "123"); final String expected = "https: assertEquals(expected, authorizeUrl); }
public static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope, @NotNull final String state) { return "https: + "&redirect_uri=" + WeChatUtils.urlEncode(redirectUri) + "&response_type=code&scope=" + scope.getScope() + "&state=" + state + "#wechat_redirect"; }
WeChatMpUtils { public static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope, @NotNull final String state) { return "https: + "&redirect_uri=" + WeChatUtils.urlEncode(redirectUri) + "&response_type=code&scope=" + scope.getScope() + "&state=" + state + "#wechat_redirect"; } }
WeChatMpUtils { public static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope, @NotNull final String state) { return "https: + "&redirect_uri=" + WeChatUtils.urlEncode(redirectUri) + "&response_type=code&scope=" + scope.getScope() + "&state=" + state + "#wechat_redirect"; } }
WeChatMpUtils { public static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope, @NotNull final String state) { return "https: + "&redirect_uri=" + WeChatUtils.urlEncode(redirectUri) + "&response_type=code&scope=" + scope.getScope() + "&state=" + state + "#wechat_redirect"; } static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope, @NotNull final String state); static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope); static void checkResponseBody(final WeChatMpResponse response); }
WeChatMpUtils { public static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope, @NotNull final String state) { return "https: + "&redirect_uri=" + WeChatUtils.urlEncode(redirectUri) + "&response_type=code&scope=" + scope.getScope() + "&state=" + state + "#wechat_redirect"; } static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope, @NotNull final String state); static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope); static void checkResponseBody(final WeChatMpResponse response); }
@Test public void generateAuthorizeUrlNoState() { final String authorizeUrl = WeChatMpUtils.generateAuthorizeUrl("wx520c15f417810387", "https: AuthorizeScope.BASE); final String expected = "https: assertEquals(expected, authorizeUrl); }
public static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope, @NotNull final String state) { return "https: + "&redirect_uri=" + WeChatUtils.urlEncode(redirectUri) + "&response_type=code&scope=" + scope.getScope() + "&state=" + state + "#wechat_redirect"; }
WeChatMpUtils { public static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope, @NotNull final String state) { return "https: + "&redirect_uri=" + WeChatUtils.urlEncode(redirectUri) + "&response_type=code&scope=" + scope.getScope() + "&state=" + state + "#wechat_redirect"; } }
WeChatMpUtils { public static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope, @NotNull final String state) { return "https: + "&redirect_uri=" + WeChatUtils.urlEncode(redirectUri) + "&response_type=code&scope=" + scope.getScope() + "&state=" + state + "#wechat_redirect"; } }
WeChatMpUtils { public static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope, @NotNull final String state) { return "https: + "&redirect_uri=" + WeChatUtils.urlEncode(redirectUri) + "&response_type=code&scope=" + scope.getScope() + "&state=" + state + "#wechat_redirect"; } static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope, @NotNull final String state); static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope); static void checkResponseBody(final WeChatMpResponse response); }
WeChatMpUtils { public static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope, @NotNull final String state) { return "https: + "&redirect_uri=" + WeChatUtils.urlEncode(redirectUri) + "&response_type=code&scope=" + scope.getScope() + "&state=" + state + "#wechat_redirect"; } static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope, @NotNull final String state); static String generateAuthorizeUrl( @NotNull final String appId, @NotNull final String redirectUri, @NotNull final AuthorizeScope scope); static void checkResponseBody(final WeChatMpResponse response); }
@Test public void weChatPayClient() throws Exception { ClassPool.getDefault().makeClass("cn.javaer.wechat.spring.boot.starter.pay.ConditionalOnClassTrigger").toClass(); try (AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext()) { context.register(WeChatPayAutoConfiguration.class); context.refresh(); context.getBean(WeChatPayClient.class); } }
@Bean @ConditionalOnMissingBean public WeChatPayClient weChatPayClient( @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @Autowired(required = false) RestTemplate restTemplate) { if (null == restTemplate) { restTemplate = new RestTemplate(); } return new WeChatPayRestTemplateClient(restTemplate, this.weChatPayProperties); }
WeChatPayAutoConfiguration { @Bean @ConditionalOnMissingBean public WeChatPayClient weChatPayClient( @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @Autowired(required = false) RestTemplate restTemplate) { if (null == restTemplate) { restTemplate = new RestTemplate(); } return new WeChatPayRestTemplateClient(restTemplate, this.weChatPayProperties); } }
WeChatPayAutoConfiguration { @Bean @ConditionalOnMissingBean public WeChatPayClient weChatPayClient( @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @Autowired(required = false) RestTemplate restTemplate) { if (null == restTemplate) { restTemplate = new RestTemplate(); } return new WeChatPayRestTemplateClient(restTemplate, this.weChatPayProperties); } WeChatPayAutoConfiguration(final WeChatPayProperties weChatPayProperties); }
WeChatPayAutoConfiguration { @Bean @ConditionalOnMissingBean public WeChatPayClient weChatPayClient( @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @Autowired(required = false) RestTemplate restTemplate) { if (null == restTemplate) { restTemplate = new RestTemplate(); } return new WeChatPayRestTemplateClient(restTemplate, this.weChatPayProperties); } WeChatPayAutoConfiguration(final WeChatPayProperties weChatPayProperties); @Bean @ConditionalOnMissingBean WeChatPayClient weChatPayClient( @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @Autowired(required = false) RestTemplate restTemplate); @Bean @ConditionalOnMissingBean WeChatPayService weChatPayService( final WeChatPayClient weChatPayClient, final ApplicationEventPublisher publisher); @Bean @ConditionalOnMissingBean WeChatPayController weChatPayController(final ApplicationEventPublisher publisher); }
WeChatPayAutoConfiguration { @Bean @ConditionalOnMissingBean public WeChatPayClient weChatPayClient( @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @Autowired(required = false) RestTemplate restTemplate) { if (null == restTemplate) { restTemplate = new RestTemplate(); } return new WeChatPayRestTemplateClient(restTemplate, this.weChatPayProperties); } WeChatPayAutoConfiguration(final WeChatPayProperties weChatPayProperties); @Bean @ConditionalOnMissingBean WeChatPayClient weChatPayClient( @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") @Autowired(required = false) RestTemplate restTemplate); @Bean @ConditionalOnMissingBean WeChatPayService weChatPayService( final WeChatPayClient weChatPayClient, final ApplicationEventPublisher publisher); @Bean @ConditionalOnMissingBean WeChatPayController weChatPayController(final ApplicationEventPublisher publisher); }
@Test public void encodeLength() throws IOException { ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(50); int codedLength = BerLength.encodeLength(os, 128); assertEquals(2, codedLength); byte[] expectedBytes = new byte[] {(byte) 0x81, (byte) 128}; assertArrayEquals(expectedBytes, os.getArray()); }
public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } BerLength(); }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } BerLength(); static int encodeLength(OutputStream reverseOS, int length); static int readEocByte(InputStream is); int decode(InputStream is); int readEocIfIndefinite(InputStream is); }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } BerLength(); static int encodeLength(OutputStream reverseOS, int length); static int readEocByte(InputStream is); int decode(InputStream is); int readEocIfIndefinite(InputStream is); public int val; }
@Test public void implicitEncoding5() throws IOException { ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50); IntegerUnivPrim testInteger = new IntegerUnivPrim(BigInteger.valueOf(128)); int length = testInteger.encode(berBAOStream, false); assertEquals(3, length); byte[] expectedBytes = new byte[] {0x02, 0x00, (byte) 0x80}; assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
@Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); static final BerTag tag; public BigInteger value; }
@Test public void implicitEncoding6() throws IOException { ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50); IntegerUnivPrim testInteger = new IntegerUnivPrim(BigInteger.valueOf(-128)); int length = testInteger.encode(berBAOStream, false); assertEquals(2, length); byte[] expectedBytes = new byte[] {0x01, (byte) 0x80}; assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
@Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); static final BerTag tag; public BigInteger value; }
@Test public void implicitEncoding7() throws IOException { ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50); IntegerUnivPrim testInteger = new IntegerUnivPrim(BigInteger.valueOf(-129)); int length = testInteger.encode(berBAOStream, false); assertEquals(3, length); byte[] expectedBytes = new byte[] {0x02, (byte) 0xff, (byte) 0x7f}; assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
@Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); static final BerTag tag; public BigInteger value; }
@Test public void explicitEncoding() throws IOException { ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50); BerInteger testInteger = new BerInteger(BigInteger.valueOf(51)); int length = testInteger.encode(berStream, true); assertEquals(3, length); byte[] expectedBytes = new byte[] {0x02, 0x01, 0x33}; assertArrayEquals(expectedBytes, berStream.getArray()); }
@Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); static final BerTag tag; public BigInteger value; }
@Test public void explicitEncoding2() throws IOException { ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50); BerInteger testInteger = new BerInteger(BigInteger.valueOf(5555)); int length = testInteger.encode(berStream, true); assertEquals(4, length); byte[] expectedBytes = new byte[] {0x02, 0x02, 0x15, (byte) 0xb3}; assertArrayEquals(expectedBytes, berStream.getArray()); }
@Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); static final BerTag tag; public BigInteger value; }
@Test public void explicitEncoding() throws IOException { ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50); byte[] byteArray = new byte[] {0x01, 0x02, 0x03}; BerOctetString asn1OctetString = new BerOctetString(byteArray); int length = asn1OctetString.encode(berStream, true); assertEquals(5, length); byte[] expectedBytes = new byte[] {0x04, 0x03, 0x01, 0x02, 0x03}; assertArrayEquals(expectedBytes, berStream.getArray()); }
@Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); }
BerOctetString implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } }
BerOctetString implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerOctetString(); BerOctetString(byte[] value); }
BerOctetString implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerOctetString(); BerOctetString(byte[] value); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); @Override String toString(); }
BerOctetString implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerOctetString(); BerOctetString(byte[] value); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); @Override String toString(); static final BerTag tag; public byte[] value; }
@Test public void explicitDecoding() throws IOException { byte[] byteCode = new byte[] {0x04, 0x00}; ByteArrayInputStream berInputStream = new ByteArrayInputStream(byteCode); BerOctetString asn1OctetString = new BerOctetString(); asn1OctetString.decode(berInputStream, true); assertEquals(0, asn1OctetString.value.length); }
@Override public int decode(InputStream is) throws IOException { return decode(is, true); }
BerOctetString implements Serializable, BerType { @Override public int decode(InputStream is) throws IOException { return decode(is, true); } }
BerOctetString implements Serializable, BerType { @Override public int decode(InputStream is) throws IOException { return decode(is, true); } BerOctetString(); BerOctetString(byte[] value); }
BerOctetString implements Serializable, BerType { @Override public int decode(InputStream is) throws IOException { return decode(is, true); } BerOctetString(); BerOctetString(byte[] value); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); @Override String toString(); }
BerOctetString implements Serializable, BerType { @Override public int decode(InputStream is) throws IOException { return decode(is, true); } BerOctetString(); BerOctetString(byte[] value); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); @Override String toString(); static final BerTag tag; public byte[] value; }
@Test public void toStringTest() { BerOctetString octetString = new BerOctetString(new byte[] {1, 2, (byte) 0xa0}); assertEquals("0102A0", octetString.toString()); }
@Override public String toString() { return HexString.fromBytes(value); }
BerOctetString implements Serializable, BerType { @Override public String toString() { return HexString.fromBytes(value); } }
BerOctetString implements Serializable, BerType { @Override public String toString() { return HexString.fromBytes(value); } BerOctetString(); BerOctetString(byte[] value); }
BerOctetString implements Serializable, BerType { @Override public String toString() { return HexString.fromBytes(value); } BerOctetString(); BerOctetString(byte[] value); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); @Override String toString(); }
BerOctetString implements Serializable, BerType { @Override public String toString() { return HexString.fromBytes(value); } BerOctetString(); BerOctetString(byte[] value); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); @Override String toString(); static final BerTag tag; public byte[] value; }
@Test public void explicitEncoding() throws IOException { ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50); BerObjectIdentifier oi = new BerObjectIdentifier(objectIdentifierComponents); int length = oi.encode(berBAOStream, true); assertEquals(7, length); assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
@Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); }
BerObjectIdentifier implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } }
BerObjectIdentifier implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerObjectIdentifier(); BerObjectIdentifier(byte[] code); BerObjectIdentifier(int[] value); }
BerObjectIdentifier implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerObjectIdentifier(); BerObjectIdentifier(byte[] code); BerObjectIdentifier(int[] value); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); @Override String toString(); }
BerObjectIdentifier implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerObjectIdentifier(); BerObjectIdentifier(byte[] code); BerObjectIdentifier(int[] value); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); @Override String toString(); static final BerTag tag; public int[] value; }
@Test public void explicitDecoding() throws IOException { ByteArrayInputStream berInputStream = new ByteArrayInputStream(expectedBytes); BerObjectIdentifier oi = new BerObjectIdentifier(); oi.decode(berInputStream, true); assertArrayEquals(objectIdentifierComponents, oi.value); ByteArrayInputStream berInputStream2 = new ByteArrayInputStream(expectedBytes2); BerObjectIdentifier oi2 = new BerObjectIdentifier(); oi2.decode(berInputStream2, true); }
@Override public int decode(InputStream is) throws IOException { return decode(is, true); }
BerObjectIdentifier implements Serializable, BerType { @Override public int decode(InputStream is) throws IOException { return decode(is, true); } }
BerObjectIdentifier implements Serializable, BerType { @Override public int decode(InputStream is) throws IOException { return decode(is, true); } BerObjectIdentifier(); BerObjectIdentifier(byte[] code); BerObjectIdentifier(int[] value); }
BerObjectIdentifier implements Serializable, BerType { @Override public int decode(InputStream is) throws IOException { return decode(is, true); } BerObjectIdentifier(); BerObjectIdentifier(byte[] code); BerObjectIdentifier(int[] value); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); @Override String toString(); }
BerObjectIdentifier implements Serializable, BerType { @Override public int decode(InputStream is) throws IOException { return decode(is, true); } BerObjectIdentifier(); BerObjectIdentifier(byte[] code); BerObjectIdentifier(int[] value); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); @Override String toString(); static final BerTag tag; public int[] value; }
@Test public void encodeLength2() throws IOException { ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(50); int codedLength = BerLength.encodeLength(os, 128); assertEquals(2, codedLength); byte[] expectedBytes = new byte[] {(byte) 0x81, (byte) 128}; assertArrayEquals(expectedBytes, os.getArray()); }
public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } BerLength(); }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } BerLength(); static int encodeLength(OutputStream reverseOS, int length); static int readEocByte(InputStream is); int decode(InputStream is); int readEocIfIndefinite(InputStream is); }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } BerLength(); static int encodeLength(OutputStream reverseOS, int length); static int readEocByte(InputStream is); int decode(InputStream is); int readEocIfIndefinite(InputStream is); public int val; }
@Test public void explicitEncoding() throws IOException { ReverseByteArrayOutputStream berStream = new ReverseByteArrayOutputStream(50); byte[] byteArray = new byte[] {0x01, 0x02, 0x03}; BerGeneralizedTime berGeneralizedTime = new BerGeneralizedTime(byteArray); int length = berGeneralizedTime.encode(berStream, true); assertEquals(5, length); byte[] expectedBytes = new byte[] {24, 0x03, 0x01, 0x02, 0x03}; assertArrayEquals(expectedBytes, berStream.getArray()); }
@Override public int encode(OutputStream reverseOS, boolean withTag) throws IOException { int codeLength = super.encode(reverseOS, false); if (withTag) { codeLength += tag.encode(reverseOS); } return codeLength; }
BerGeneralizedTime extends BerVisibleString { @Override public int encode(OutputStream reverseOS, boolean withTag) throws IOException { int codeLength = super.encode(reverseOS, false); if (withTag) { codeLength += tag.encode(reverseOS); } return codeLength; } }
BerGeneralizedTime extends BerVisibleString { @Override public int encode(OutputStream reverseOS, boolean withTag) throws IOException { int codeLength = super.encode(reverseOS, false); if (withTag) { codeLength += tag.encode(reverseOS); } return codeLength; } BerGeneralizedTime(); BerGeneralizedTime(byte[] value); BerGeneralizedTime(String valueAsString); }
BerGeneralizedTime extends BerVisibleString { @Override public int encode(OutputStream reverseOS, boolean withTag) throws IOException { int codeLength = super.encode(reverseOS, false); if (withTag) { codeLength += tag.encode(reverseOS); } return codeLength; } BerGeneralizedTime(); BerGeneralizedTime(byte[] value); BerGeneralizedTime(String valueAsString); @Override int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is, boolean withTag); Calendar asCalendar(); Date asDate(); }
BerGeneralizedTime extends BerVisibleString { @Override public int encode(OutputStream reverseOS, boolean withTag) throws IOException { int codeLength = super.encode(reverseOS, false); if (withTag) { codeLength += tag.encode(reverseOS); } return codeLength; } BerGeneralizedTime(); BerGeneralizedTime(byte[] value); BerGeneralizedTime(String valueAsString); @Override int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is, boolean withTag); Calendar asCalendar(); Date asDate(); static final BerTag tag; }
@Test public void toStringTest() { BerBitString bitString = new BerBitString(new byte[] {1, 2, 7}, 23); assertEquals("00000001000000100000011", bitString.toString()); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); for (boolean bit : getValueAsBooleans()) { if (bit) { sb.append('1'); } else { sb.append('0'); } } return sb.toString(); }
BerBitString implements Serializable, BerType { @Override public String toString() { StringBuilder sb = new StringBuilder(); for (boolean bit : getValueAsBooleans()) { if (bit) { sb.append('1'); } else { sb.append('0'); } } return sb.toString(); } }
BerBitString implements Serializable, BerType { @Override public String toString() { StringBuilder sb = new StringBuilder(); for (boolean bit : getValueAsBooleans()) { if (bit) { sb.append('1'); } else { sb.append('0'); } } return sb.toString(); } BerBitString(); BerBitString(byte[] value, int numBits); BerBitString(boolean[] value); BerBitString(byte[] code); }
BerBitString implements Serializable, BerType { @Override public String toString() { StringBuilder sb = new StringBuilder(); for (boolean bit : getValueAsBooleans()) { if (bit) { sb.append('1'); } else { sb.append('0'); } } return sb.toString(); } BerBitString(); BerBitString(byte[] value, int numBits); BerBitString(boolean[] value); BerBitString(byte[] code); boolean[] getValueAsBooleans(); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); @Override String toString(); }
BerBitString implements Serializable, BerType { @Override public String toString() { StringBuilder sb = new StringBuilder(); for (boolean bit : getValueAsBooleans()) { if (bit) { sb.append('1'); } else { sb.append('0'); } } return sb.toString(); } BerBitString(); BerBitString(byte[] value, int numBits); BerBitString(boolean[] value); BerBitString(byte[] code); boolean[] getValueAsBooleans(); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); @Override String toString(); static final BerTag tag; public byte[] value; public int numBits; }
@Test public void toString2Test() { BerBitString bitString = new BerBitString( new boolean[] { false, false, false, false, false, false, false, true, false, false, false, false, false, false, true, false, false, false, false, false, false, true, true }); assertEquals("00000001000000100000011", bitString.toString()); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); for (boolean bit : getValueAsBooleans()) { if (bit) { sb.append('1'); } else { sb.append('0'); } } return sb.toString(); }
BerBitString implements Serializable, BerType { @Override public String toString() { StringBuilder sb = new StringBuilder(); for (boolean bit : getValueAsBooleans()) { if (bit) { sb.append('1'); } else { sb.append('0'); } } return sb.toString(); } }
BerBitString implements Serializable, BerType { @Override public String toString() { StringBuilder sb = new StringBuilder(); for (boolean bit : getValueAsBooleans()) { if (bit) { sb.append('1'); } else { sb.append('0'); } } return sb.toString(); } BerBitString(); BerBitString(byte[] value, int numBits); BerBitString(boolean[] value); BerBitString(byte[] code); }
BerBitString implements Serializable, BerType { @Override public String toString() { StringBuilder sb = new StringBuilder(); for (boolean bit : getValueAsBooleans()) { if (bit) { sb.append('1'); } else { sb.append('0'); } } return sb.toString(); } BerBitString(); BerBitString(byte[] value, int numBits); BerBitString(boolean[] value); BerBitString(byte[] code); boolean[] getValueAsBooleans(); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); @Override String toString(); }
BerBitString implements Serializable, BerType { @Override public String toString() { StringBuilder sb = new StringBuilder(); for (boolean bit : getValueAsBooleans()) { if (bit) { sb.append('1'); } else { sb.append('0'); } } return sb.toString(); } BerBitString(); BerBitString(byte[] value, int numBits); BerBitString(boolean[] value); BerBitString(byte[] code); boolean[] getValueAsBooleans(); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); @Override String toString(); static final BerTag tag; public byte[] value; public int numBits; }
@Test public void encodeLength3() throws IOException { ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(50); int codedLength = BerLength.encodeLength(os, 65536); assertEquals(4, codedLength); byte[] expectedBytes = new byte[] {(byte) 0x83, 1, 0, 0}; assertArrayEquals(expectedBytes, os.getArray()); }
public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } BerLength(); }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } BerLength(); static int encodeLength(OutputStream reverseOS, int length); static int readEocByte(InputStream is); int decode(InputStream is); int readEocIfIndefinite(InputStream is); }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } BerLength(); static int encodeLength(OutputStream reverseOS, int length); static int readEocByte(InputStream is); int decode(InputStream is); int readEocIfIndefinite(InputStream is); public int val; }
@Test public void encodeLength4() throws IOException { ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(50); int codedLength = BerLength.encodeLength(os, 256); assertEquals(3, codedLength); byte[] expectedBytes = new byte[] {(byte) 0x82, 1, 0}; assertArrayEquals(expectedBytes, os.getArray()); }
public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } BerLength(); }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } BerLength(); static int encodeLength(OutputStream reverseOS, int length); static int readEocByte(InputStream is); int decode(InputStream is); int readEocIfIndefinite(InputStream is); }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } BerLength(); static int encodeLength(OutputStream reverseOS, int length); static int readEocByte(InputStream is); int decode(InputStream is); int readEocIfIndefinite(InputStream is); public int val; }
@Test public void encodeLength5() throws IOException { ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(50); int codedLength = BerLength.encodeLength(os, 16777216); assertEquals(5, codedLength); byte[] expectedBytes = new byte[] {(byte) 0x84, 1, 0, 0, 0}; assertArrayEquals(expectedBytes, os.getArray()); }
public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } BerLength(); }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } BerLength(); static int encodeLength(OutputStream reverseOS, int length); static int readEocByte(InputStream is); int decode(InputStream is); int readEocIfIndefinite(InputStream is); }
BerLength implements Serializable { public static int encodeLength(OutputStream reverseOS, int length) throws IOException { if (length <= 127) { reverseOS.write(length); return 1; } if (length <= 255) { reverseOS.write(length); reverseOS.write(0x81); return 2; } if (length <= 65535) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(0x82); return 3; } if (length <= 16777215) { reverseOS.write(length); reverseOS.write(length >> 8); reverseOS.write(length >> 16); reverseOS.write(0x83); return 4; } int numLengthBytes = 1; while (((int) (Math.pow(2, 8 * numLengthBytes) - 1)) < length) { numLengthBytes++; } for (int i = 0; i < numLengthBytes; i++) { reverseOS.write(length >> (8 * i)); } reverseOS.write(0x80 | numLengthBytes); return 1 + numLengthBytes; } BerLength(); static int encodeLength(OutputStream reverseOS, int length); static int readEocByte(InputStream is); int decode(InputStream is); int readEocIfIndefinite(InputStream is); public int val; }
@Test public void explicitDecoding() throws IOException { byte[] byteCode = new byte[] {(byte) 0x81, (byte) 128}; ByteArrayInputStream berInputStream = new ByteArrayInputStream(byteCode); BerLength berLength = new BerLength(); berLength.decode(berInputStream); assertEquals(128, berLength.val); }
public int decode(InputStream is) throws IOException { val = is.read(); if (val < 128) { if (val == -1) { throw new EOFException("Unexpected end of input stream."); } return 1; } int lengthLength = val & 0x7f; if (lengthLength == 0) { val = -1; return 1; } if (lengthLength > 4) { throw new IOException("Length is out of bounds: " + lengthLength); } val = 0; for (int i = 0; i < lengthLength; i++) { int nextByte = is.read(); if (nextByte == -1) { throw new EOFException("Unexpected end of input stream."); } val |= nextByte << (8 * (lengthLength - i - 1)); } return lengthLength + 1; }
BerLength implements Serializable { public int decode(InputStream is) throws IOException { val = is.read(); if (val < 128) { if (val == -1) { throw new EOFException("Unexpected end of input stream."); } return 1; } int lengthLength = val & 0x7f; if (lengthLength == 0) { val = -1; return 1; } if (lengthLength > 4) { throw new IOException("Length is out of bounds: " + lengthLength); } val = 0; for (int i = 0; i < lengthLength; i++) { int nextByte = is.read(); if (nextByte == -1) { throw new EOFException("Unexpected end of input stream."); } val |= nextByte << (8 * (lengthLength - i - 1)); } return lengthLength + 1; } }
BerLength implements Serializable { public int decode(InputStream is) throws IOException { val = is.read(); if (val < 128) { if (val == -1) { throw new EOFException("Unexpected end of input stream."); } return 1; } int lengthLength = val & 0x7f; if (lengthLength == 0) { val = -1; return 1; } if (lengthLength > 4) { throw new IOException("Length is out of bounds: " + lengthLength); } val = 0; for (int i = 0; i < lengthLength; i++) { int nextByte = is.read(); if (nextByte == -1) { throw new EOFException("Unexpected end of input stream."); } val |= nextByte << (8 * (lengthLength - i - 1)); } return lengthLength + 1; } BerLength(); }
BerLength implements Serializable { public int decode(InputStream is) throws IOException { val = is.read(); if (val < 128) { if (val == -1) { throw new EOFException("Unexpected end of input stream."); } return 1; } int lengthLength = val & 0x7f; if (lengthLength == 0) { val = -1; return 1; } if (lengthLength > 4) { throw new IOException("Length is out of bounds: " + lengthLength); } val = 0; for (int i = 0; i < lengthLength; i++) { int nextByte = is.read(); if (nextByte == -1) { throw new EOFException("Unexpected end of input stream."); } val |= nextByte << (8 * (lengthLength - i - 1)); } return lengthLength + 1; } BerLength(); static int encodeLength(OutputStream reverseOS, int length); static int readEocByte(InputStream is); int decode(InputStream is); int readEocIfIndefinite(InputStream is); }
BerLength implements Serializable { public int decode(InputStream is) throws IOException { val = is.read(); if (val < 128) { if (val == -1) { throw new EOFException("Unexpected end of input stream."); } return 1; } int lengthLength = val & 0x7f; if (lengthLength == 0) { val = -1; return 1; } if (lengthLength > 4) { throw new IOException("Length is out of bounds: " + lengthLength); } val = 0; for (int i = 0; i < lengthLength; i++) { int nextByte = is.read(); if (nextByte == -1) { throw new EOFException("Unexpected end of input stream."); } val |= nextByte << (8 * (lengthLength - i - 1)); } return lengthLength + 1; } BerLength(); static int encodeLength(OutputStream reverseOS, int length); static int readEocByte(InputStream is); int decode(InputStream is); int readEocIfIndefinite(InputStream is); public int val; }
@Test public void implicitEncoding1() throws IOException { ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50); IntegerUnivPrim testInteger = new IntegerUnivPrim(BigInteger.valueOf(51)); int length = testInteger.encode(berBAOStream, false); assertEquals(2, length); byte[] expectedBytes = new byte[] {0x01, 0x33}; assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
@Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); static final BerTag tag; public BigInteger value; }
@Test public void implicitEncoding2() throws IOException { ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50); IntegerUnivPrim testInteger = new IntegerUnivPrim(BigInteger.valueOf(256)); int length = testInteger.encode(berBAOStream, false); assertEquals(3, length); byte[] expectedBytes = new byte[] {0x02, 0x01, 0x00}; assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
@Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); static final BerTag tag; public BigInteger value; }
@Test public void implicitEncoding3() throws IOException { ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50); IntegerUnivPrim testInteger = new IntegerUnivPrim(BigInteger.valueOf(0)); int length = testInteger.encode(berBAOStream, false); assertEquals(2, length); byte[] expectedBytes = new byte[] {0x01, 0x00}; assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
@Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); static final BerTag tag; public BigInteger value; }
@Test public void implicitEncoding4() throws IOException { ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50); IntegerUnivPrim testInteger = new IntegerUnivPrim(BigInteger.valueOf(127)); int length = testInteger.encode(berBAOStream, false); assertEquals(2, length); byte[] expectedBytes = new byte[] {0x01, 0x7f}; assertArrayEquals(expectedBytes, berBAOStream.getArray()); }
@Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); }
BerInteger implements Serializable, BerType { @Override public int encode(OutputStream reverseOS) throws IOException { return encode(reverseOS, true); } BerInteger(); BerInteger(byte[] code); BerInteger(BigInteger val); BerInteger(long val); @Override int encode(OutputStream reverseOS); int encode(OutputStream reverseOS, boolean withTag); @Override int decode(InputStream is); int decode(InputStream is, boolean withTag); void encodeAndSave(int encodingSizeGuess); @Override String toString(); byte byteValue(); short shortValue(); int intValue(); long longValue(); static final BerTag tag; public BigInteger value; }
@Test public void testFederationType() { assertThat(metaStore.getFederationType(), is(FederationType.PRIMARY)); }
@Override public FederationType getFederationType() { return FederationType.PRIMARY; }
PrimaryMetaStore extends AbstractMetaStore { @Override public FederationType getFederationType() { return FederationType.PRIMARY; } }
PrimaryMetaStore extends AbstractMetaStore { @Override public FederationType getFederationType() { return FederationType.PRIMARY; } PrimaryMetaStore(); PrimaryMetaStore( String name, String remoteMetaStoreUris, AccessControlType accessControlType, String... writableDatabaseWhitelist); PrimaryMetaStore( String name, String remoteMetaStoreUris, AccessControlType accessControlType, List<String> writableDatabaseWhitelist); }
PrimaryMetaStore extends AbstractMetaStore { @Override public FederationType getFederationType() { return FederationType.PRIMARY; } PrimaryMetaStore(); PrimaryMetaStore( String name, String remoteMetaStoreUris, AccessControlType accessControlType, String... writableDatabaseWhitelist); PrimaryMetaStore( String name, String remoteMetaStoreUris, AccessControlType accessControlType, List<String> writableDatabaseWhitelist); @Override FederationType getFederationType(); @NotNull @Override String getDatabasePrefix(); }
PrimaryMetaStore extends AbstractMetaStore { @Override public FederationType getFederationType() { return FederationType.PRIMARY; } PrimaryMetaStore(); PrimaryMetaStore( String name, String remoteMetaStoreUris, AccessControlType accessControlType, String... writableDatabaseWhitelist); PrimaryMetaStore( String name, String remoteMetaStoreUris, AccessControlType accessControlType, List<String> writableDatabaseWhitelist); @Override FederationType getFederationType(); @NotNull @Override String getDatabasePrefix(); }
@Test public void getMetastoreMappingName() throws Exception { when(metaStoreMapping.getMetastoreMappingName()).thenReturn("Name"); String result = decorator.getMetastoreMappingName(); assertThat(result, is("Name")); }
@Override public String getMetastoreMappingName() { return metaStoreMapping.getMetastoreMappingName(); }
MetaStoreMappingDecorator implements MetaStoreMapping { @Override public String getMetastoreMappingName() { return metaStoreMapping.getMetastoreMappingName(); } }
MetaStoreMappingDecorator implements MetaStoreMapping { @Override public String getMetastoreMappingName() { return metaStoreMapping.getMetastoreMappingName(); } MetaStoreMappingDecorator(MetaStoreMapping metaStoreMapping); }
MetaStoreMappingDecorator implements MetaStoreMapping { @Override public String getMetastoreMappingName() { return metaStoreMapping.getMetastoreMappingName(); } MetaStoreMappingDecorator(MetaStoreMapping metaStoreMapping); @Override String transformOutboundDatabaseName(String databaseName); @Override List<String> transformOutboundDatabaseNameMultiple(String databaseName); @Override Database transformOutboundDatabase(Database database); @Override String transformInboundDatabaseName(String databaseName); @Override void close(); @Override Iface getClient(); @Override String getDatabasePrefix(); @Override String getMetastoreMappingName(); @Override boolean isAvailable(); @Override MetaStoreMapping checkWritePermissions(String databaseName); @Override void createDatabase(Database database); @Override long getLatency(); }
MetaStoreMappingDecorator implements MetaStoreMapping { @Override public String getMetastoreMappingName() { return metaStoreMapping.getMetastoreMappingName(); } MetaStoreMappingDecorator(MetaStoreMapping metaStoreMapping); @Override String transformOutboundDatabaseName(String databaseName); @Override List<String> transformOutboundDatabaseNameMultiple(String databaseName); @Override Database transformOutboundDatabase(Database database); @Override String transformInboundDatabaseName(String databaseName); @Override void close(); @Override Iface getClient(); @Override String getDatabasePrefix(); @Override String getMetastoreMappingName(); @Override boolean isAvailable(); @Override MetaStoreMapping checkWritePermissions(String databaseName); @Override void createDatabase(Database database); @Override long getLatency(); }