All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.webauthn4j.credential.CoreCredentialRecordImpl Maven / Gradle / Ivy

There is a newer version: 0.9.2.RELEASE
Show newest version
package com.webauthn4j.credential;

import com.webauthn4j.authenticator.CoreAuthenticatorImpl;
import com.webauthn4j.data.attestation.AttestationObject;
import com.webauthn4j.data.attestation.authenticator.AttestedCredentialData;
import com.webauthn4j.data.attestation.statement.AttestationStatement;
import com.webauthn4j.data.extension.authenticator.AuthenticationExtensionsAuthenticatorOutputs;
import com.webauthn4j.data.extension.authenticator.RegistrationExtensionAuthenticatorOutput;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

import static com.webauthn4j.data.attestation.authenticator.AuthenticatorData.*;

public class CoreCredentialRecordImpl extends CoreAuthenticatorImpl implements CoreCredentialRecord{

    private Boolean uvInitialized;
    private Boolean backupEligible;
    private Boolean backupState;

    public CoreCredentialRecordImpl(@NotNull AttestationObject attestationObject){

        //As AttestationObject always have AttestedCredentialData, this won't be an issue
        //noinspection DataFlowIssue
        super(attestationObject.getAuthenticatorData().getAttestedCredentialData(),
                attestationObject.getAttestationStatement(),
                attestationObject.getAuthenticatorData().getSignCount(),
                attestationObject.getAuthenticatorData().getExtensions());
        this.uvInitialized = (attestationObject.getAuthenticatorData().getFlags() & BIT_UV) != 0;
        this.backupEligible = (attestationObject.getAuthenticatorData().getFlags() & BIT_BE) != 0;
        this.backupState = (attestationObject.getAuthenticatorData().getFlags() & BIT_BS) != 0;
    }

    public CoreCredentialRecordImpl(
            @Nullable AttestationStatement attestationStatement,
            @Nullable Boolean uvInitialized,
            @Nullable Boolean backupEligible,
            @Nullable Boolean backupState,
            long counter,
            @NotNull AttestedCredentialData attestedCredentialData,
            @Nullable AuthenticationExtensionsAuthenticatorOutputs authenticatorExtensions) {
        super(attestedCredentialData, attestationStatement, counter, authenticatorExtensions);
        this.uvInitialized = uvInitialized;
        this.backupEligible = backupEligible;
        this.backupState = backupState;
    }

    @Override
    public Boolean isUvInitialized() {
        return this.uvInitialized;
    }

    @Override
    public void setUvInitialized(boolean value) {
        this.uvInitialized = value;
    }

    @Override
    public Boolean isBackupEligible() {
        return this.backupEligible;
    }

    @Override
    public void setBackupEligible(boolean value) {
        this.backupEligible = value;
    }

    @Override
    public Boolean isBackedUp() {
        return this.backupState;
    }

    @Override
    public void setBackedUp(boolean value) {
        this.backupState = value;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;
        CoreCredentialRecordImpl that = (CoreCredentialRecordImpl) o;
        return Objects.equals(uvInitialized, that.uvInitialized) && Objects.equals(backupEligible, that.backupEligible) && Objects.equals(backupState, that.backupState);
    }

    @Override
    public int hashCode() {
        return Objects.hash(super.hashCode(), uvInitialized, backupEligible, backupState);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy