@Test void serialize_deserialize_test() { byte[] rpIdHash = new byte[32]; byte flags = BIT_ED; AuthenticationExtensionsAuthenticatorOutputs.BuilderForRegistration builder = new AuthenticationExtensionsAuthenticatorOutputs.BuilderForRegistration(); builder.setUvm(new UvmEntries()); AuthenticatorData<RegistrationExtensionAuthenticatorOutput> authenticatorData = new AuthenticatorData<>(rpIdHash, flags, 0, builder.build()); byte[] serialized = new AuthenticatorDataConverter(objectConverter).convert(authenticatorData); AuthenticatorData<RegistrationExtensionAuthenticatorOutput> result = new AuthenticatorDataConverter(objectConverter).convert(serialized); assertThat(result.getRpIdHash()).isNotNull(); assertThat(result.getRpIdHash()).hasSize(32); assertThat(result.getFlags()).isEqualTo(BIT_ED); assertThat(result.getSignCount()).isZero(); assertThat(result.getAttestedCredentialData()).isNull(); assertThat(result.getExtensions().getKeys()).contains(UserVerificationMethodExtensionAuthenticatorOutput.ID); }
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);  }