@Test public void fromString() throws DecoderException { for ( int i = 0; i < 2; i++ ) { for ( int j = 0; j < 40; j++ ) { String oidStr = i + "." + j; byte[] expected = new byte[]{ ( byte ) ( i * 40 + j ) }; byte[] oidBytes = Oid.fromString( oidStr ).toBytes(); assertTrue( Arrays.equals( expected, oidBytes ) ); } } assertTrue( Arrays.equals( new byte[] { 0x2A, ( byte ) 0x86, 0x48, ( byte ) 0x86, ( byte ) 0xF7, 0x12, 0x01, 0x02, 0x02 }, Oid.fromString( "1.2.840.113554.1.2.2" ).toBytes() ) ); }
public static Oid fromString( String oidString ) throws DecoderException { if ( ( oidString == null ) || oidString.isEmpty() ) { throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "empty" ) ); } byte[] buffer = new byte[oidString.length()]; OidFSAState state = OidFSAState.START; int arcNbChars = 0; int bufPos = 0; int startArc = 0; int nbBytes; for ( int i = 0; i < oidString.length(); i++ ) { switch ( state ) { case START : state = processStateStart( oidString, buffer, i ); break; case STATE_A : state = processStateA( oidString, i ); break; case STATE_B : state = processStateB( oidString, buffer, i ); break; case STATE_C : state = processStateC( oidString, buffer, i ); bufPos = 1; break; case STATE_D : case STATE_E : state = processStateDE( oidString, buffer, i ); bufPos = 1; break; case STATE_F : state = processStateF( oidString, i ); break; case STATE_G : state = processStateG( oidString, buffer, i ); arcNbChars = 1; startArc = i; break; case STATE_H : state = processStateH( oidString, buffer, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars = 2; bufPos = 0; } break; case STATE_I : state = processStateI( oidString, buffer, i ); bufPos = 1; break; case STATE_J : state = processStateJ( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars++; } else { bufPos += convert( oidString, buffer, bufPos, arcNbChars, 0, true ); } break; case STATE_K : startArc = i; state = processStateK( oidString, buffer, bufPos, i ); if ( state == OidFSAState.STATE_M ) { bufPos++; } else { arcNbChars = 1; } break; case STATE_L : state = processStateL( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_L ) { arcNbChars++; break; } else { bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); } break; case STATE_M : state = processStateM( oidString, i ); break; default : break; } } switch ( state ) { case STATE_C : case STATE_D : case STATE_E : case STATE_H : case STATE_I : byte[] bytes = new byte[1]; bytes[0] = ( byte ) ( buffer[0] | buffer[1] ); return new Oid( oidString, bytes ); case STATE_J : nbBytes = convert( oidString, buffer, 2, arcNbChars, 0, true ); bytes = new byte[nbBytes]; System.arraycopy( buffer, 0, bytes, 0, nbBytes ); return new Oid( oidString, bytes ); case STATE_L : bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); case STATE_M : bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); default : throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "Wrong OID" ) ); } }
Oid { public static Oid fromString( String oidString ) throws DecoderException { if ( ( oidString == null ) || oidString.isEmpty() ) { throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "empty" ) ); } byte[] buffer = new byte[oidString.length()]; OidFSAState state = OidFSAState.START; int arcNbChars = 0; int bufPos = 0; int startArc = 0; int nbBytes; for ( int i = 0; i < oidString.length(); i++ ) { switch ( state ) { case START : state = processStateStart( oidString, buffer, i ); break; case STATE_A : state = processStateA( oidString, i ); break; case STATE_B : state = processStateB( oidString, buffer, i ); break; case STATE_C : state = processStateC( oidString, buffer, i ); bufPos = 1; break; case STATE_D : case STATE_E : state = processStateDE( oidString, buffer, i ); bufPos = 1; break; case STATE_F : state = processStateF( oidString, i ); break; case STATE_G : state = processStateG( oidString, buffer, i ); arcNbChars = 1; startArc = i; break; case STATE_H : state = processStateH( oidString, buffer, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars = 2; bufPos = 0; } break; case STATE_I : state = processStateI( oidString, buffer, i ); bufPos = 1; break; case STATE_J : state = processStateJ( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars++; } else { bufPos += convert( oidString, buffer, bufPos, arcNbChars, 0, true ); } break; case STATE_K : startArc = i; state = processStateK( oidString, buffer, bufPos, i ); if ( state == OidFSAState.STATE_M ) { bufPos++; } else { arcNbChars = 1; } break; case STATE_L : state = processStateL( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_L ) { arcNbChars++; break; } else { bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); } break; case STATE_M : state = processStateM( oidString, i ); break; default : break; } } switch ( state ) { case STATE_C : case STATE_D : case STATE_E : case STATE_H : case STATE_I : byte[] bytes = new byte[1]; bytes[0] = ( byte ) ( buffer[0] | buffer[1] ); return new Oid( oidString, bytes ); case STATE_J : nbBytes = convert( oidString, buffer, 2, arcNbChars, 0, true ); bytes = new byte[nbBytes]; System.arraycopy( buffer, 0, bytes, 0, nbBytes ); return new Oid( oidString, bytes ); case STATE_L : bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); case STATE_M : bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); default : throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "Wrong OID" ) ); } } }
Oid { public static Oid fromString( String oidString ) throws DecoderException { if ( ( oidString == null ) || oidString.isEmpty() ) { throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "empty" ) ); } byte[] buffer = new byte[oidString.length()]; OidFSAState state = OidFSAState.START; int arcNbChars = 0; int bufPos = 0; int startArc = 0; int nbBytes; for ( int i = 0; i < oidString.length(); i++ ) { switch ( state ) { case START : state = processStateStart( oidString, buffer, i ); break; case STATE_A : state = processStateA( oidString, i ); break; case STATE_B : state = processStateB( oidString, buffer, i ); break; case STATE_C : state = processStateC( oidString, buffer, i ); bufPos = 1; break; case STATE_D : case STATE_E : state = processStateDE( oidString, buffer, i ); bufPos = 1; break; case STATE_F : state = processStateF( oidString, i ); break; case STATE_G : state = processStateG( oidString, buffer, i ); arcNbChars = 1; startArc = i; break; case STATE_H : state = processStateH( oidString, buffer, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars = 2; bufPos = 0; } break; case STATE_I : state = processStateI( oidString, buffer, i ); bufPos = 1; break; case STATE_J : state = processStateJ( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars++; } else { bufPos += convert( oidString, buffer, bufPos, arcNbChars, 0, true ); } break; case STATE_K : startArc = i; state = processStateK( oidString, buffer, bufPos, i ); if ( state == OidFSAState.STATE_M ) { bufPos++; } else { arcNbChars = 1; } break; case STATE_L : state = processStateL( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_L ) { arcNbChars++; break; } else { bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); } break; case STATE_M : state = processStateM( oidString, i ); break; default : break; } } switch ( state ) { case STATE_C : case STATE_D : case STATE_E : case STATE_H : case STATE_I : byte[] bytes = new byte[1]; bytes[0] = ( byte ) ( buffer[0] | buffer[1] ); return new Oid( oidString, bytes ); case STATE_J : nbBytes = convert( oidString, buffer, 2, arcNbChars, 0, true ); bytes = new byte[nbBytes]; System.arraycopy( buffer, 0, bytes, 0, nbBytes ); return new Oid( oidString, bytes ); case STATE_L : bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); case STATE_M : bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); default : throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "Wrong OID" ) ); } } private  Oid( String oidString, byte[] oidBytes ); }
Oid { public static Oid fromString( String oidString ) throws DecoderException { if ( ( oidString == null ) || oidString.isEmpty() ) { throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "empty" ) ); } byte[] buffer = new byte[oidString.length()]; OidFSAState state = OidFSAState.START; int arcNbChars = 0; int bufPos = 0; int startArc = 0; int nbBytes; for ( int i = 0; i < oidString.length(); i++ ) { switch ( state ) { case START : state = processStateStart( oidString, buffer, i ); break; case STATE_A : state = processStateA( oidString, i ); break; case STATE_B : state = processStateB( oidString, buffer, i ); break; case STATE_C : state = processStateC( oidString, buffer, i ); bufPos = 1; break; case STATE_D : case STATE_E : state = processStateDE( oidString, buffer, i ); bufPos = 1; break; case STATE_F : state = processStateF( oidString, i ); break; case STATE_G : state = processStateG( oidString, buffer, i ); arcNbChars = 1; startArc = i; break; case STATE_H : state = processStateH( oidString, buffer, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars = 2; bufPos = 0; } break; case STATE_I : state = processStateI( oidString, buffer, i ); bufPos = 1; break; case STATE_J : state = processStateJ( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars++; } else { bufPos += convert( oidString, buffer, bufPos, arcNbChars, 0, true ); } break; case STATE_K : startArc = i; state = processStateK( oidString, buffer, bufPos, i ); if ( state == OidFSAState.STATE_M ) { bufPos++; } else { arcNbChars = 1; } break; case STATE_L : state = processStateL( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_L ) { arcNbChars++; break; } else { bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); } break; case STATE_M : state = processStateM( oidString, i ); break; default : break; } } switch ( state ) { case STATE_C : case STATE_D : case STATE_E : case STATE_H : case STATE_I : byte[] bytes = new byte[1]; bytes[0] = ( byte ) ( buffer[0] | buffer[1] ); return new Oid( oidString, bytes ); case STATE_J : nbBytes = convert( oidString, buffer, 2, arcNbChars, 0, true ); bytes = new byte[nbBytes]; System.arraycopy( buffer, 0, bytes, 0, nbBytes ); return new Oid( oidString, bytes ); case STATE_L : bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); case STATE_M : bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); default : throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "Wrong OID" ) ); } } private  Oid( String oidString, byte[] oidBytes ); @Override boolean equals( Object other ); static Oid fromBytes( byte[] oidBytes ); static Oid fromString( String oidString ); int getEncodedLength(); @Override int hashCode(); static boolean isOid( String oidString ); byte[] toBytes(); @Override String toString(); void writeBytesTo( ByteBuffer buffer ); void writeBytesTo( OutputStream outputStream ); }
Oid { public static Oid fromString( String oidString ) throws DecoderException { if ( ( oidString == null ) || oidString.isEmpty() ) { throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "empty" ) ); } byte[] buffer = new byte[oidString.length()]; OidFSAState state = OidFSAState.START; int arcNbChars = 0; int bufPos = 0; int startArc = 0; int nbBytes; for ( int i = 0; i < oidString.length(); i++ ) { switch ( state ) { case START : state = processStateStart( oidString, buffer, i ); break; case STATE_A : state = processStateA( oidString, i ); break; case STATE_B : state = processStateB( oidString, buffer, i ); break; case STATE_C : state = processStateC( oidString, buffer, i ); bufPos = 1; break; case STATE_D : case STATE_E : state = processStateDE( oidString, buffer, i ); bufPos = 1; break; case STATE_F : state = processStateF( oidString, i ); break; case STATE_G : state = processStateG( oidString, buffer, i ); arcNbChars = 1; startArc = i; break; case STATE_H : state = processStateH( oidString, buffer, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars = 2; bufPos = 0; } break; case STATE_I : state = processStateI( oidString, buffer, i ); bufPos = 1; break; case STATE_J : state = processStateJ( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_J ) { arcNbChars++; } else { bufPos += convert( oidString, buffer, bufPos, arcNbChars, 0, true ); } break; case STATE_K : startArc = i; state = processStateK( oidString, buffer, bufPos, i ); if ( state == OidFSAState.STATE_M ) { bufPos++; } else { arcNbChars = 1; } break; case STATE_L : state = processStateL( oidString, buffer, arcNbChars + bufPos, i ); if ( state == OidFSAState.STATE_L ) { arcNbChars++; break; } else { bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); } break; case STATE_M : state = processStateM( oidString, i ); break; default : break; } } switch ( state ) { case STATE_C : case STATE_D : case STATE_E : case STATE_H : case STATE_I : byte[] bytes = new byte[1]; bytes[0] = ( byte ) ( buffer[0] | buffer[1] ); return new Oid( oidString, bytes ); case STATE_J : nbBytes = convert( oidString, buffer, 2, arcNbChars, 0, true ); bytes = new byte[nbBytes]; System.arraycopy( buffer, 0, bytes, 0, nbBytes ); return new Oid( oidString, bytes ); case STATE_L : bufPos += convert( oidString, buffer, startArc, arcNbChars, bufPos, false ); bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); case STATE_M : bytes = new byte[bufPos]; System.arraycopy( buffer, 0, bytes, 0, bufPos ); return new Oid( oidString, bytes ); default : throw new DecoderException( I18n.err( I18n.ERR_00003_INVALID_OID, "Wrong OID" ) ); } } private  Oid( String oidString, byte[] oidBytes ); @Override boolean equals( Object other ); static Oid fromBytes( byte[] oidBytes ); static Oid fromString( String oidString ); int getEncodedLength(); @Override int hashCode(); static boolean isOid( String oidString ); byte[] toBytes(); @Override String toString(); void writeBytesTo( ByteBuffer buffer ); void writeBytesTo( OutputStream outputStream );  }