@Test void convert_test() { String input = "SZYN5YgOjGh0NBcPZHZgW4_krrmihjLHmVzzuoMdl2MBAAABRQ"; AuthenticatorData<RegistrationExtensionAuthenticatorOutput> result = new AuthenticatorDataConverter(objectConverter).convert(Base64UrlUtil.decode(input)); assertThat(result.getRpIdHash()).isNotNull(); assertThat(result.getRpIdHash()).hasSize(32); assertThat(result.getFlags()).isEqualTo(BIT_UP); assertThat(result.getSignCount()).isEqualTo(325); assertThat(result.getAttestedCredentialData()).isNull(); assertThat(result.getExtensions().getKeys()).isEmpty(); }
public <T extends ExtensionAuthenticatorOutput> byte[] convert(AuthenticatorData<T> source) { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] rpIdHash = source.getRpIdHash(); byteArrayOutputStream.write(rpIdHash); byteArrayOutputStream.write(new byte[]{source.getFlags()}); byteArrayOutputStream.write(UnsignedNumberUtil.toBytes(source.getSignCount())); if (source.getAttestedCredentialData() != null) { byteArrayOutputStream.write(attestedCredentialDataConverter.convert(source.getAttestedCredentialData())); } byteArrayOutputStream.write(convert(source.getExtensions())); return byteArrayOutputStream.toByteArray(); } catch (IOException e) { throw new UncheckedIOException(e); } }
AuthenticatorDataConverter { public <T extends ExtensionAuthenticatorOutput> byte[] convert(AuthenticatorData<T> source) { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] rpIdHash = source.getRpIdHash(); byteArrayOutputStream.write(rpIdHash); byteArrayOutputStream.write(new byte[]{source.getFlags()}); byteArrayOutputStream.write(UnsignedNumberUtil.toBytes(source.getSignCount())); if (source.getAttestedCredentialData() != null) { byteArrayOutputStream.write(attestedCredentialDataConverter.convert(source.getAttestedCredentialData())); } byteArrayOutputStream.write(convert(source.getExtensions())); return byteArrayOutputStream.toByteArray(); } catch (IOException e) { throw new UncheckedIOException(e); } } }
AuthenticatorDataConverter { public <T extends ExtensionAuthenticatorOutput> byte[] convert(AuthenticatorData<T> source) { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] rpIdHash = source.getRpIdHash(); byteArrayOutputStream.write(rpIdHash); byteArrayOutputStream.write(new byte[]{source.getFlags()}); byteArrayOutputStream.write(UnsignedNumberUtil.toBytes(source.getSignCount())); if (source.getAttestedCredentialData() != null) { byteArrayOutputStream.write(attestedCredentialDataConverter.convert(source.getAttestedCredentialData())); } byteArrayOutputStream.write(convert(source.getExtensions())); return byteArrayOutputStream.toByteArray(); } catch (IOException e) { throw new UncheckedIOException(e); } } AuthenticatorDataConverter(ObjectConverter objectConverter); }
AuthenticatorDataConverter { public <T extends ExtensionAuthenticatorOutput> byte[] convert(AuthenticatorData<T> source) { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] rpIdHash = source.getRpIdHash(); byteArrayOutputStream.write(rpIdHash); byteArrayOutputStream.write(new byte[]{source.getFlags()}); byteArrayOutputStream.write(UnsignedNumberUtil.toBytes(source.getSignCount())); if (source.getAttestedCredentialData() != null) { byteArrayOutputStream.write(attestedCredentialDataConverter.convert(source.getAttestedCredentialData())); } byteArrayOutputStream.write(convert(source.getExtensions())); return byteArrayOutputStream.toByteArray(); } catch (IOException e) { throw new UncheckedIOException(e); } } AuthenticatorDataConverter(ObjectConverter objectConverter); byte[] convert(AuthenticatorData<T> source); AuthenticatorData<T> convert(byte[] source); byte[] extractAttestedCredentialData(byte[] authenticatorData); long extractSignCount(byte[] authenticatorData); }
AuthenticatorDataConverter { public <T extends ExtensionAuthenticatorOutput> byte[] convert(AuthenticatorData<T> source) { try { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byte[] rpIdHash = source.getRpIdHash(); byteArrayOutputStream.write(rpIdHash); byteArrayOutputStream.write(new byte[]{source.getFlags()}); byteArrayOutputStream.write(UnsignedNumberUtil.toBytes(source.getSignCount())); if (source.getAttestedCredentialData() != null) { byteArrayOutputStream.write(attestedCredentialDataConverter.convert(source.getAttestedCredentialData())); } byteArrayOutputStream.write(convert(source.getExtensions())); return byteArrayOutputStream.toByteArray(); } catch (IOException e) { throw new UncheckedIOException(e); } } AuthenticatorDataConverter(ObjectConverter objectConverter); byte[] convert(AuthenticatorData<T> source); AuthenticatorData<T> convert(byte[] source); byte[] extractAttestedCredentialData(byte[] authenticatorData); long extractSignCount(byte[] authenticatorData);  }