Skip to content

Commit

Permalink
Expose optional features with `any(all(doc, not(doctest)), feature(..…
Browse files Browse the repository at this point in the history
….))'.

This fixes broken documentation links, and gives nice banners when building
docs on nightly (which docs.rs does).
  • Loading branch information
micolous committed Apr 7, 2024
1 parent bb75b93 commit e74dfd3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 32 deletions.
66 changes: 39 additions & 27 deletions webauthn-rs/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl PartialEq for Passkey {
feature = "danger-allow-state-serialisation",
derive(Serialize, Deserialize)
)]
#[cfg(feature = "attestation")]
#[cfg(any(all(doc, not(doctest)), feature = "attestation"))]
pub struct AttestedPasskeyRegistration {
pub(crate) rs: RegistrationState,
pub(crate) ca_list: AttestationCaList,
Expand All @@ -167,7 +167,7 @@ pub struct AttestedPasskeyRegistration {
feature = "danger-allow-state-serialisation",
derive(Serialize, Deserialize)
)]
#[cfg(feature = "attestation")]
#[cfg(any(all(doc, not(doctest)), feature = "attestation"))]
pub struct AttestedPasskeyAuthentication {
pub(crate) ast: AuthenticationState,
}
Expand All @@ -178,12 +178,12 @@ pub struct AttestedPasskeyAuthentication {
///
/// These can be safely serialised and deserialised from a database for use.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg(feature = "attestation")]
#[cfg(any(all(doc, not(doctest)), feature = "attestation"))]
pub struct AttestedPasskey {
pub(crate) cred: Credential,
}

#[cfg(feature = "attestation")]
#[cfg(any(all(doc, not(doctest)), feature = "attestation"))]
impl AttestedPasskey {
/// Retrieve a reference to this AttestedPasskey Key's credential ID.
pub fn cred_id(&self) -> &CredentialID {
Expand Down Expand Up @@ -252,38 +252,38 @@ impl AttestedPasskey {
}
}

#[cfg(feature = "attestation")]
#[cfg(any(all(doc, not(doctest)), feature = "attestation"))]
impl std::borrow::Borrow<CredentialID> for AttestedPasskey {
fn borrow(&self) -> &CredentialID {
&self.cred.cred_id
}
}

#[cfg(feature = "attestation")]
#[cfg(any(all(doc, not(doctest)), feature = "attestation"))]
impl PartialEq for AttestedPasskey {
fn eq(&self, other: &Self) -> bool {
self.cred.cred_id == other.cred.cred_id
}
}

#[cfg(feature = "attestation")]
#[cfg(any(all(doc, not(doctest)), feature = "attestation"))]
impl Eq for AttestedPasskey {}

#[cfg(feature = "attestation")]
#[cfg(any(all(doc, not(doctest)), feature = "attestation"))]
impl PartialOrd for AttestedPasskey {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cred.cred_id.cmp(&other.cred.cred_id))
}
}

#[cfg(feature = "attestation")]
#[cfg(any(all(doc, not(doctest)), feature = "attestation"))]
impl Ord for AttestedPasskey {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.cred.cred_id.cmp(&other.cred.cred_id)
}
}

#[cfg(feature = "attestation")]
#[cfg(any(all(doc, not(doctest)), feature = "attestation"))]
impl From<&AttestedPasskey> for Passkey {
fn from(k: &AttestedPasskey) -> Self {
Passkey {
Expand All @@ -292,7 +292,7 @@ impl From<&AttestedPasskey> for Passkey {
}
}

#[cfg(feature = "attestation")]
#[cfg(any(all(doc, not(doctest)), feature = "attestation"))]
impl From<AttestedPasskey> for Passkey {
fn from(k: AttestedPasskey) -> Self {
Passkey { cred: k.cred }
Expand Down Expand Up @@ -430,7 +430,7 @@ impl From<Credential> for SecurityKey {
}
}

/// An in progress registration session for a [AttestedResidentKey].
/// An in progress registration session for an [AttestedResidentKey].
///
/// WARNING ⚠️ YOU MUST STORE THIS VALUE SERVER SIDE.
///
Expand All @@ -444,7 +444,7 @@ impl From<Credential> for SecurityKey {
feature = "danger-allow-state-serialisation",
derive(Serialize, Deserialize)
)]
#[cfg(feature = "resident-key-support")]
#[cfg(any(all(doc, not(doctest)), feature = "resident-key-support"))]
pub struct AttestedResidentKeyRegistration {
pub(crate) rs: RegistrationState,
pub(crate) ca_list: AttestationCaList,
Expand All @@ -464,7 +464,7 @@ pub struct AttestedResidentKeyRegistration {
feature = "danger-allow-state-serialisation",
derive(Serialize, Deserialize)
)]
#[cfg(feature = "resident-key-support")]
#[cfg(any(all(doc, not(doctest)), feature = "resident-key-support"))]
pub struct AttestedResidentKeyAuthentication {
pub(crate) ast: AuthenticationState,
}
Expand All @@ -482,12 +482,12 @@ pub struct AttestedResidentKeyAuthentication {
///
/// These can be safely serialised and deserialised from a database for use.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg(feature = "resident-key-support")]
#[cfg(any(all(doc, not(doctest)), feature = "resident-key-support"))]
pub struct AttestedResidentKey {
pub(crate) cred: Credential,
}

#[cfg(feature = "resident-key-support")]
#[cfg(any(all(doc, not(doctest)), feature = "resident-key-support"))]
impl AttestedResidentKey {
/// Retrieve a reference to this Resident Key's credential ID.
pub fn cred_id(&self) -> &CredentialID {
Expand Down Expand Up @@ -556,14 +556,14 @@ impl AttestedResidentKey {
}
}

#[cfg(feature = "resident-key-support")]
#[cfg(any(all(doc, not(doctest)), feature = "resident-key-support"))]
impl PartialEq for AttestedResidentKey {
fn eq(&self, other: &Self) -> bool {
self.cred.cred_id == other.cred.cred_id
}
}

#[cfg(feature = "resident-key-support")]
#[cfg(any(all(doc, not(doctest)), feature = "resident-key-support"))]
impl From<&AttestedResidentKey> for Passkey {
fn from(k: &AttestedResidentKey) -> Self {
Passkey {
Expand All @@ -572,7 +572,7 @@ impl From<&AttestedResidentKey> for Passkey {
}
}

#[cfg(feature = "resident-key-support")]
#[cfg(any(all(doc, not(doctest)), feature = "resident-key-support"))]
impl From<AttestedResidentKey> for Passkey {
fn from(k: AttestedResidentKey) -> Self {
Passkey { cred: k.cred }
Expand Down Expand Up @@ -615,7 +615,7 @@ impl From<Credential> for AttestedResidentKey {
feature = "danger-allow-state-serialisation",
derive(Serialize, Deserialize)
)]
#[cfg(feature = "conditional-ui")]
#[cfg(any(all(doc, not(doctest)), feature = "conditional-ui"))]
pub struct DiscoverableAuthentication {
pub(crate) ast: AuthenticationState,
}
Expand All @@ -626,12 +626,15 @@ pub struct DiscoverableAuthentication {
/// Generally this is used as part of conditional ui which allows autofill of discovered
/// credentials in username fields.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg(feature = "conditional-ui")]
#[cfg(any(all(doc, not(doctest)), feature = "conditional-ui"))]
pub struct DiscoverableKey {
pub(crate) cred: Credential,
}

#[cfg(all(feature = "conditional-ui", feature = "resident-key-support"))]
#[cfg(any(
all(doc, not(doctest)),
all(feature = "conditional-ui", feature = "resident-key-support")
))]
impl From<&AttestedResidentKey> for DiscoverableKey {
fn from(k: &AttestedResidentKey) -> Self {
DiscoverableKey {
Expand All @@ -640,14 +643,20 @@ impl From<&AttestedResidentKey> for DiscoverableKey {
}
}

#[cfg(all(feature = "conditional-ui", feature = "resident-key-support"))]
#[cfg(any(
all(doc, not(doctest)),
all(feature = "conditional-ui", feature = "resident-key-support")
))]
impl From<AttestedResidentKey> for DiscoverableKey {
fn from(k: AttestedResidentKey) -> Self {
DiscoverableKey { cred: k.cred }
}
}

#[cfg(all(feature = "conditional-ui", feature = "attestation"))]
#[cfg(any(
all(doc, not(doctest)),
all(feature = "conditional-ui", feature = "attestation")
))]
impl From<&AttestedPasskey> for DiscoverableKey {
fn from(k: &AttestedPasskey) -> Self {
DiscoverableKey {
Expand All @@ -656,14 +665,17 @@ impl From<&AttestedPasskey> for DiscoverableKey {
}
}

#[cfg(all(feature = "conditional-ui", feature = "attestation"))]
#[cfg(any(
all(doc, not(doctest)),
all(feature = "conditional-ui", feature = "attestation")
))]
impl From<AttestedPasskey> for DiscoverableKey {
fn from(k: AttestedPasskey) -> Self {
DiscoverableKey { cred: k.cred }
}
}

#[cfg(feature = "conditional-ui")]
#[cfg(any(all(doc, not(doctest)), feature = "conditional-ui"))]
impl From<&Passkey> for DiscoverableKey {
fn from(k: &Passkey) -> Self {
DiscoverableKey {
Expand All @@ -672,7 +684,7 @@ impl From<&Passkey> for DiscoverableKey {
}
}

#[cfg(feature = "conditional-ui")]
#[cfg(any(all(doc, not(doctest)), feature = "conditional-ui"))]
impl From<Passkey> for DiscoverableKey {
fn from(k: Passkey) -> Self {
DiscoverableKey { cred: k.cred }
Expand Down
13 changes: 8 additions & 5 deletions webauthn-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ impl<'a> WebauthnBuilder<'a> {
/// You **MUST** only use it in tightly controlled environments where you supply devices to your
/// users.
///
/// > You should use [`start_attested_resident_key_registration`](Webauthn::start_attested_resident_key_registration) (still in development)
/// > You should use [`start_attested_resident_key_registration`](Webauthn::start_attested_resident_key_registration) (still in development, requires `resident-key-support` feature)
///
///
/// __I want a security token along with an external password to create multi-factor authentication__
Expand Down Expand Up @@ -591,7 +591,10 @@ impl Webauthn {
/// on your site ahead of time to choose between a security key / screen unlock
/// (triggered by [`start_passkey_registration`](Webauthn::start_passkey_registration))
/// or a 'Google Passkey stored in Google Password Manager' (triggered by this function).
#[cfg(feature = "workaround-google-passkey-specific-issues")]
#[cfg(any(
all(doc, not(doctest)),
feature = "workaround-google-passkey-specific-issues"
))]
pub fn start_google_passkey_in_google_password_manager_only_registration(
&self,
user_unique_id: Uuid,
Expand Down Expand Up @@ -988,7 +991,7 @@ impl Webauthn {
}
}

#[cfg(feature = "attestation")]
#[cfg(any(all(doc, not(doctest)), feature = "attestation"))]
impl Webauthn {
/// Initiate the registration of a new attested_passkey key for a user. A attested_passkey key is a
/// cryptographic authenticator that is a self-contained multifactor authenticator. This means
Expand Down Expand Up @@ -1266,7 +1269,7 @@ impl Webauthn {
}
}

#[cfg(feature = "conditional-ui")]
#[cfg(any(all(doc, not(doctest)), feature = "conditional-ui"))]
impl Webauthn {
/// This function will initiate a conditional ui authentication for discoverable
/// credentials.
Expand Down Expand Up @@ -1350,7 +1353,7 @@ impl Webauthn {
}
}

#[cfg(feature = "resident-key-support")]
#[cfg(any(all(doc, not(doctest)), feature = "resident-key-support"))]
impl Webauthn {
/// TODO
pub fn start_attested_resident_key_registration(
Expand Down

0 comments on commit e74dfd3

Please sign in to comment.