@@ -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,7 +276,7 @@ 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
@@ -291,7 +292,8 @@ pub struct PublicKeyCredentialParameters {
291292 /// > because it will be serialized into a message to the authenticator, which may be
292293 /// > sent over a low-bandwidth link.
293294 #[ serde( with = "i64_to_iana" ) ]
294- #[ typeshare( serialized_as = "I54" ) ] // because i64 fails for js
295+ #[ cfg_attr( feature = "typeshare" , typeshare( serialized_as = "I54" ) ) ]
296+ // because i64 fails for js
295297 pub alg : iana:: Algorithm ,
296298}
297299
@@ -325,7 +327,7 @@ impl PublicKeyCredentialParameters {
325327/// [Relying Parties]: https://w3c.github.io/webauthn/#webauthn-relying-party
326328#[ derive( Debug , Default , Serialize , Deserialize ) ]
327329#[ serde( rename_all = "camelCase" ) ]
328- #[ typeshare]
330+ #[ cfg_attr ( feature = " typeshare" , typeshare ) ]
329331pub struct AuthenticatorSelectionCriteria {
330332 /// If this member is present, eligible authenticators are filtered to be only those
331333 /// authenticators attached with the specified [`AuthenticatorAttachment`] modality. If this
@@ -387,7 +389,7 @@ pub struct AuthenticatorSelectionCriteria {
387389/// [discoverable credential]: https://w3c.github.io/webauthn/#client-side-discoverable-credential
388390#[ derive( Debug , Deserialize , Serialize , Clone , Copy , PartialEq , Eq ) ]
389391#[ serde( rename_all = "lowercase" ) ]
390- #[ typeshare( serialized_as = "String" ) ]
392+ #[ cfg_attr ( feature = " typeshare" , typeshare ( serialized_as = "String" ) ) ]
391393pub enum ResidentKeyRequirement {
392394 /// The Relying Party prefers creating a [server-side credential], but will accept a client-side
393395 /// discoverable credential. The client and authenticator SHOULD create a server-side credential
@@ -424,7 +426,7 @@ pub enum ResidentKeyRequirement {
424426/// [attestation conveyance]: https://w3c.github.io/webauthn/#attestation-conveyance
425427#[ derive( Debug , Default , Deserialize , Serialize , Clone , Copy , PartialEq , Eq ) ]
426428#[ serde( rename_all = "lowercase" ) ]
427- #[ typeshare( serialized_as = "String" ) ]
429+ #[ cfg_attr ( feature = " typeshare" , typeshare ( serialized_as = "String" ) ) ]
428430pub enum AttestationConveyancePreference {
429431 /// The Relying Party is not interested in authenticator attestation. For example, in order to
430432 /// potentially avoid having to obtain user consent to relay identifying information to the
@@ -473,7 +475,7 @@ pub enum AttestationConveyancePreference {
473475/// [2]: https://w3c.github.io/webauthn/#sctn-attstn-fmt-ids
474476#[ derive( Debug , Default , Deserialize , Serialize , Clone , Copy , PartialEq , Eq ) ]
475477#[ serde( rename_all = "kebab-case" ) ]
476- #[ typeshare]
478+ #[ cfg_attr ( feature = " typeshare" , typeshare ) ]
477479pub enum AttestationStatementFormatIdentifiers {
478480 /// The `packed` attestation statement format is a WebAuthn-optimized format for attestation.
479481 /// It uses a very compact but still extensible encoding method. This format is implementable by
@@ -515,7 +517,7 @@ pub enum AttestationStatementFormatIdentifiers {
515517/// [Relying Party]: https://w3c.github.io/webauthn/#relying-party
516518#[ derive( Debug , Clone , Deserialize , Serialize ) ]
517519#[ serde( rename_all = "camelCase" ) ]
518- #[ typeshare( swift = "Equatable, Hashable" ) ]
520+ #[ cfg_attr ( feature = " typeshare" , typeshare ( swift = "Equatable, Hashable" ) ) ]
519521pub struct AuthenticatorAttestationResponse {
520522 /// This attribute contains the JSON serialization of [`CollectedClientData`] passed to the
521523 /// authenticator by the client in order to generate this credential. The exact JSON serialization
@@ -535,7 +537,8 @@ pub struct AuthenticatorAttestationResponse {
535537 /// This is the [CoseAlgorithmIdentifier] of the new credential
536538 ///
537539 /// [CoseAlgorithmIdentifier]: https://w3c.github.io/webauthn/#typedefdef-cosealgorithmidentifier
538- #[ typeshare( serialized_as = "I54" ) ] // because i64 fails for js
540+ #[ cfg_attr( feature = "typeshare" , typeshare( serialized_as = "I54" ) ) ]
541+ // ^ because i64 fails for js
539542 pub public_key_algorithm : i64 ,
540543
541544 /// This attribute contains an attestation object, which is opaque to, and cryptographically
@@ -625,7 +628,7 @@ where
625628
626629/// Used to limit the values of [`CollectedClientData::ty`] and serializes to static strings.
627630#[ derive( Debug , Deserialize , Serialize , Clone , Copy , PartialEq , Eq ) ]
628- #[ typeshare]
631+ #[ cfg_attr ( feature = " typeshare" , typeshare ) ]
629632pub enum ClientDataType {
630633 /// Serializes to the string `"webauthn.create"`
631634 #[ serde( rename = "webauthn.create" ) ]
0 commit comments