Skip to main content

NonDiscoverableAuthenticationClientState

Struct NonDiscoverableAuthenticationClientState 

Source
pub struct NonDiscoverableAuthenticationClientState<'rp_id, 'prf_first, 'prf_second>(/* private fields */);
Expand description

Container of a NonDiscoverableCredentialRequestOptions that has been used to start the authentication ceremony. This gets sent to the client ASAP.

Implementations§

Source§

impl<'rp_id, 'prf_first, 'prf_second> NonDiscoverableAuthenticationClientState<'rp_id, 'prf_first, 'prf_second>

Source

pub const fn options( &self, ) -> &NonDiscoverableCredentialRequestOptions<'rp_id, 'prf_first, 'prf_second>

Returns the NonDiscoverableCredentialRequestOptions that was used to start an authentication ceremony.

Trait Implementations§

Source§

impl<'rp_id, 'prf_first, 'prf_second> Debug for NonDiscoverableAuthenticationClientState<'rp_id, 'prf_first, 'prf_second>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for NonDiscoverableAuthenticationClientState<'_, '_, '_>

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serializes self according to NonDiscoverableCredentialRequestOptions::serialize.

§Examples
/// Retrieves the `AuthTransports` associated with the unique `cred_id`
/// from the database.
fn get_transports(cred_id: CredentialId<&[u8]>) -> Result<AuthTransports, DecodeAuthTransportsErr> {
    // ⋮
}
let mut creds = AllowedCredentials::with_capacity(1);
// `CredentialId::try_from` only exists when `custom` is enabled; and even then, it is
// likely never needed since the `CredentialId` was originally sent from the client and is likely
// stored in a database which would be fetched by `UserHandle` or `Authentication::raw_id`.
let id = CredentialId::try_from(vec![0; 16].into_boxed_slice())?;
let transports = get_transports((&id).into())?;
creds.push(AllowedCredential {
    credential: PublicKeyCredentialDescriptor { id, transports },
    extension: CredentialSpecificExtension {
        prf: Some(PrfInputOwned {
            first: vec![2; 6],
            second: Some(vec![3; 2]),
            ext_req: ExtensionReq::Require,
        }),
    },
});
let rp_id = RpId::Domain(AsciiDomain::try_from("example.com".to_owned())?);
let mut options = NonDiscoverableCredentialRequestOptions::second_factor(&rp_id, creds);
let opts = &mut options.options;
opts.hints = Hints::EMPTY.add(PublicKeyCredentialHint::SecurityKey);
// This is actually useless since `CredentialSpecificExtension` takes priority
// when the client receives the payload. We set it for illustration purposes only.
// If `creds` contained an `AllowedCredential` that didn't set
// `CredentialSpecificExtension::prf`, then this would be used for it.
opts.extensions = Extension {
    prf: Some((PrfInput {
        first: [0; 4].as_slice(),
        second: None,
    }, ExtensionReq::Require)),
};
// Since we are requesting the PRF extension, we must require user verification; otherwise
// `NonDiscoverableCredentialRequestOptions::start_ceremony` would error.
opts.user_verification = UserVerificationRequirement::Required;
let client_state = serde_json::to_string(&options.start_ceremony()?.1).unwrap();
let json = serde_json::json!({
    "mediation":"required",
    "publicKey":{
        "challenge":"AAAAAAAAAAAAAAAAAAAAAA",
        "timeout":300000,
        "rpId":"example.com",
        "allowCredentials":[
            {
                "type":"public-key",
                "id":"AAAAAAAAAAAAAAAAAAAAAA",
                "transports":["usb"]
            }
        ],
        "userVerification":"required",
        "hints":[
            "security-key"
        ],
        "extensions":{
            "prf":{
                "eval":{
                    "first":"AAAAAA"
                },
                "evalByCredential":{
                    "AAAAAAAAAAAAAAAAAAAAAA":{
                        "first":"AgICAgIC",
                        "second":"AwM"
                    }
                }
            }
        }
    }
}).to_string();
// Since `Challenge`s are randomly generated, we don't know what it will be; thus
// we test the JSON string for everything except it.
assert_eq!(client_state.get(..50), json.get(..50));
assert_eq!(client_state.get(72..), json.get(72..));

Auto Trait Implementations§

§

impl<'rp_id, 'prf_first, 'prf_second> Freeze for NonDiscoverableAuthenticationClientState<'rp_id, 'prf_first, 'prf_second>

§

impl<'rp_id, 'prf_first, 'prf_second> RefUnwindSafe for NonDiscoverableAuthenticationClientState<'rp_id, 'prf_first, 'prf_second>

§

impl<'rp_id, 'prf_first, 'prf_second> Send for NonDiscoverableAuthenticationClientState<'rp_id, 'prf_first, 'prf_second>

§

impl<'rp_id, 'prf_first, 'prf_second> Sync for NonDiscoverableAuthenticationClientState<'rp_id, 'prf_first, 'prf_second>

§

impl<'rp_id, 'prf_first, 'prf_second> Unpin for NonDiscoverableAuthenticationClientState<'rp_id, 'prf_first, 'prf_second>

§

impl<'rp_id, 'prf_first, 'prf_second> UnsafeUnpin for NonDiscoverableAuthenticationClientState<'rp_id, 'prf_first, 'prf_second>

§

impl<'rp_id, 'prf_first, 'prf_second> UnwindSafe for NonDiscoverableAuthenticationClientState<'rp_id, 'prf_first, 'prf_second>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.