@@ -3,6 +3,7 @@ use coset::iana;
33use indexmap:: IndexMap ;
44use serde:: { Deserialize , Serialize , Serializer } ;
55use std:: fmt;
6+ #[ cfg( feature = "typeshare" ) ]
67use typeshare:: typeshare;
78
89use crate :: {
@@ -25,7 +26,7 @@ use crate::{
2526} ;
2627
2728/// The response to the successful creation of a PublicKeyCredential
28- #[ typeshare( swift = "Equatable, Hashable" ) ]
29+ #[ cfg_attr ( feature = " typeshare" , typeshare ( swift = "Equatable, Hashable" ) ) ]
2930pub type CreatedPublicKeyCredential = PublicKeyCredential < AuthenticatorAttestationResponse > ;
3031
3132/// This is the expected input to [`navigator.credentials.create`] when wanting to create a webauthn
@@ -36,7 +37,7 @@ pub type CreatedPublicKeyCredential = PublicKeyCredential<AuthenticatorAttestati
3637/// [`navigator.credentials.create`]: https://developer.mozilla.org/en-US/docs/Web/API/CredentialsContainer/create
3738#[ derive( Debug , Serialize , Deserialize ) ]
3839#[ serde( rename_all = "camelCase" ) ]
39- #[ typeshare]
40+ #[ cfg_attr ( feature = " typeshare" , typeshare ) ]
4041pub struct CredentialCreationOptions {
4142 /// The key defining that this is a request for a webauthn credential.
4243 pub public_key : PublicKeyCredentialCreationOptions ,
@@ -47,7 +48,7 @@ pub struct CredentialCreationOptions {
4748/// <https://w3c.github.io/webauthn/#dictdef-publickeycredentialcreationoptions>
4849#[ derive( Debug , Serialize , Deserialize ) ]
4950#[ serde( rename_all = "camelCase" ) ]
50- #[ typeshare]
51+ #[ cfg_attr ( feature = " typeshare" , typeshare ) ]
5152pub struct PublicKeyCredentialCreationOptions {
5253 /// This member contains a name and an identifier for the [Relying Party] responsible for the request.
5354 ///
@@ -170,7 +171,7 @@ pub struct PublicKeyCredentialCreationOptions {
170171///
171172/// <https://w3c.github.io/webauthn/#dictdef-publickeycredentialrpentity>
172173#[ derive( Debug , Serialize , Deserialize , Clone ) ]
173- #[ typeshare]
174+ #[ cfg_attr ( feature = " typeshare" , typeshare ) ]
174175pub struct PublicKeyCredentialRpEntity {
175176 /// A unique identifier for the [Relying Party] entity, which sets the [RP ID].
176177 ///
@@ -224,7 +225,7 @@ pub struct PublicKeyCredentialRpEntity {
224225/// [Lang]: https://w3c.github.io/webauthn/#sctn-strings-langdir
225226#[ derive( Debug , Serialize , Deserialize , Clone ) ]
226227#[ serde( rename_all = "camelCase" ) ]
227- #[ typeshare]
228+ #[ cfg_attr ( feature = " typeshare" , typeshare ) ]
228229pub struct PublicKeyCredentialUserEntity {
229230 /// The user handle of the user account. A user handle is an opaque byte sequence with a maximum
230231 /// size of 64 bytes, and is not meant to be displayed to the user.
@@ -275,14 +276,15 @@ pub struct PublicKeyCredentialUserEntity {
275276///
276277/// <https://w3c.github.io/webauthn/#dictdef-publickeycredentialparameters>
277278#[ derive( Debug , Serialize , Deserialize , Clone , Copy ) ]
278- #[ typeshare]
279+ #[ cfg_attr ( feature = " typeshare" , typeshare ) ]
279280pub struct PublicKeyCredentialParameters {
280281 /// This member specifies the type of credential to be created. The value SHOULD be a member of
281282 /// [`PublicKeyCredentialType`] but client platforms MUST ignore unknown values, ignoring any
282283 /// [`PublicKeyCredentialParameters`] with an [`PublicKeyCredentialType::Unknown`] type.
283284 #[ serde( rename = "type" , deserialize_with = "ignore_unknown" ) ]
284285 pub ty : PublicKeyCredentialType ,
285286
287+ #[ cfg( feature = "typeshare" ) ]
286288 /// This member specifies the cryptographic signature algorithm with which the newly generated
287289 /// credential will be used, and thus also the type of asymmetric key pair to be generated,
288290 /// e.g., RSA or Elliptic Curve.
@@ -293,6 +295,17 @@ pub struct PublicKeyCredentialParameters {
293295 #[ serde( with = "i64_to_iana" ) ]
294296 #[ typeshare( serialized_as = "I54" ) ] // because i64 fails for js
295297 pub alg : iana:: Algorithm ,
298+
299+ #[ cfg( not( feature = "typeshare" ) ) ]
300+ /// This member specifies the cryptographic signature algorithm with which the newly generated
301+ /// credential will be used, and thus also the type of asymmetric key pair to be generated,
302+ /// e.g., RSA or Elliptic Curve.
303+ ///
304+ /// > Note: we use `alg` as the latter member name, rather than spelling-out `algorithm`,
305+ /// > because it will be serialized into a message to the authenticator, which may be
306+ /// > sent over a low-bandwidth link.
307+ #[ serde( with = "i64_to_iana" ) ]
308+ pub alg : iana:: Algorithm ,
296309}
297310
298311impl PublicKeyCredentialParameters {
@@ -325,7 +338,7 @@ impl PublicKeyCredentialParameters {
325338/// [Relying Parties]: https://w3c.github.io/webauthn/#webauthn-relying-party
326339#[ derive( Debug , Default , Serialize , Deserialize ) ]
327340#[ serde( rename_all = "camelCase" ) ]
328- #[ typeshare]
341+ #[ cfg_attr ( feature = " typeshare" , typeshare ) ]
329342pub struct AuthenticatorSelectionCriteria {
330343 /// If this member is present, eligible authenticators are filtered to be only those
331344 /// authenticators attached with the specified [`AuthenticatorAttachment`] modality. If this
@@ -387,7 +400,7 @@ pub struct AuthenticatorSelectionCriteria {
387400/// [discoverable credential]: https://w3c.github.io/webauthn/#client-side-discoverable-credential
388401#[ derive( Debug , Deserialize , Serialize , Clone , Copy , PartialEq , Eq ) ]
389402#[ serde( rename_all = "lowercase" ) ]
390- #[ typeshare( serialized_as = "String" ) ]
403+ #[ cfg_attr ( feature = " typeshare" , typeshare ( serialized_as = "String" ) ) ]
391404pub enum ResidentKeyRequirement {
392405 /// The Relying Party prefers creating a [server-side credential], but will accept a client-side
393406 /// discoverable credential. The client and authenticator SHOULD create a server-side credential
@@ -424,7 +437,7 @@ pub enum ResidentKeyRequirement {
424437/// [attestation conveyance]: https://w3c.github.io/webauthn/#attestation-conveyance
425438#[ derive( Debug , Default , Deserialize , Serialize , Clone , Copy , PartialEq , Eq ) ]
426439#[ serde( rename_all = "lowercase" ) ]
427- #[ typeshare( serialized_as = "String" ) ]
440+ #[ cfg_attr ( feature = " typeshare" , typeshare ( serialized_as = "String" ) ) ]
428441pub enum AttestationConveyancePreference {
429442 /// The Relying Party is not interested in authenticator attestation. For example, in order to
430443 /// potentially avoid having to obtain user consent to relay identifying information to the
@@ -473,7 +486,7 @@ pub enum AttestationConveyancePreference {
473486/// [2]: https://w3c.github.io/webauthn/#sctn-attstn-fmt-ids
474487#[ derive( Debug , Default , Deserialize , Serialize , Clone , Copy , PartialEq , Eq ) ]
475488#[ serde( rename_all = "kebab-case" ) ]
476- #[ typeshare]
489+ #[ cfg_attr ( feature = " typeshare" , typeshare ) ]
477490pub enum AttestationStatementFormatIdentifiers {
478491 /// The `packed` attestation statement format is a WebAuthn-optimized format for attestation.
479492 /// It uses a very compact but still extensible encoding method. This format is implementable by
@@ -515,7 +528,7 @@ pub enum AttestationStatementFormatIdentifiers {
515528/// [Relying Party]: https://w3c.github.io/webauthn/#relying-party
516529#[ derive( Debug , Clone , Deserialize , Serialize ) ]
517530#[ serde( rename_all = "camelCase" ) ]
518- #[ typeshare( swift = "Equatable, Hashable" ) ]
531+ #[ cfg_attr ( feature = " typeshare" , typeshare ( swift = "Equatable, Hashable" ) ) ]
519532pub struct AuthenticatorAttestationResponse {
520533 /// This attribute contains the JSON serialization of [`CollectedClientData`] passed to the
521534 /// authenticator by the client in order to generate this credential. The exact JSON serialization
@@ -532,12 +545,19 @@ pub struct AuthenticatorAttestationResponse {
532545 #[ serde( skip_serializing_if = "Option::is_none" ) ]
533546 pub public_key : Option < Bytes > ,
534547
548+ #[ cfg( feature = "typeshare" ) ]
535549 /// This is the [CoseAlgorithmIdentifier] of the new credential
536550 ///
537551 /// [CoseAlgorithmIdentifier]: https://w3c.github.io/webauthn/#typedefdef-cosealgorithmidentifier
538552 #[ typeshare( serialized_as = "I54" ) ] // because i64 fails for js
539553 pub public_key_algorithm : i64 ,
540554
555+ #[ cfg( not( feature = "typeshare" ) ) ]
556+ /// This is the [CoseAlgorithmIdentifier] of the new credential
557+ ///
558+ /// [CoseAlgorithmIdentifier]: https://w3c.github.io/webauthn/#typedefdef-cosealgorithmidentifier
559+ pub public_key_algorithm : i64 ,
560+
541561 /// This attribute contains an attestation object, which is opaque to, and cryptographically
542562 /// protected against tampering by, the client. The attestation object contains both
543563 /// [`AuthenticatorData`] and an attestation statement. The former contains the [`Aaguid`], a unique
@@ -625,7 +645,7 @@ where
625645
626646/// Used to limit the values of [`CollectedClientData::ty`] and serializes to static strings.
627647#[ derive( Debug , Deserialize , Serialize , Clone , Copy , PartialEq , Eq ) ]
628- #[ typeshare]
648+ #[ cfg_attr ( feature = " typeshare" , typeshare ) ]
629649pub enum ClientDataType {
630650 /// Serializes to the string `"webauthn.create"`
631651 #[ serde( rename = "webauthn.create" ) ]
0 commit comments