private LegacyCredential deserializeCredentials( String part, int lineNumber ) throws FormatException { String[] split = part.split( credentialSeparator, -1 ); if ( split.length != 3 ) { throw new FormatException( format( "wrong number of credential fields [line %d]", lineNumber ) ); } if ( !split[0].equals( LegacyCredential.DIGEST_ALGO ) ) { throw new FormatException( format( "unknown digest \"%s\" [line %d]", split[0], lineNumber ) ); } byte[] decodedPassword = HexString.decodeHexString( split[1] ); byte[] decodedSalt = HexString.decodeHexString( split[2] ); return new LegacyCredential( decodedSalt, decodedPassword ); } }
@Test void shouldDecodeStringToBytes() { byte[] result = HexString.decodeHexString( "00f34CEFFF3e02" ); byte[] expected = new byte[] {(byte) 0x00, (byte) 0xF3, (byte) 0x4C, (byte) 0xEF, (byte) 0xFF, (byte) 0x3E, (byte) 0x02 }; assertArrayEquals( expected, result ); }
@Test void shouldDecodeEmptyStringToEmptyBytes() { byte[] result = HexString.decodeHexString( "" ); assertArrayEquals( new byte[]{}, result ); } }
private LegacyCredential deserializeCredentials( String part, int lineNumber ) throws FormatException { String[] split = part.split( credentialSeparator, -1 ); if ( split.length != 3 ) { throw new FormatException( format( "wrong number of credential fields [line %d]", lineNumber ) ); } if ( !split[0].equals( LegacyCredential.DIGEST_ALGO ) ) { throw new FormatException( format( "unknown digest \"%s\" [line %d]", split[0], lineNumber ) ); } byte[] decodedPassword = HexString.decodeHexString( split[1] ); byte[] decodedSalt = HexString.decodeHexString( split[2] ); return new LegacyCredential( decodedSalt, decodedPassword ); } }