Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Make more types non-exhaustive #189

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- As a consequence the type `pipe::TrussedInterchange` becomes a const`pipe::TRUSSED_INTERCHANGE`
- Updated `littlefs2` to 0.4.0.
- Made `Request`, `Reply`, `Error`, `Context`, `CoreContext`, `Mechanism`,
`ui::Status` non-exhaustive.
`KeySerialization`, `SignatureSerialization`, `consent::Error`, `ui::Status` non-exhaustive.
- Made `postcard_deserialize`, `postcard_serialize` and
`postcard_serialize_bytes` private.
- Changed `&PathBuf` to `&Path` where possible.
Expand Down
1 change: 1 addition & 0 deletions core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub use ui::UiClient;
// to be fair, this is a programmer error,
// and could also just panic
#[derive(Copy, Clone, Debug)]
#[non_exhaustive]
pub enum ClientError {
Full,
Pending,
Expand Down
5 changes: 4 additions & 1 deletion core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub mod consent {
}

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
#[non_exhaustive]
pub enum Error {
FailedToInterrupt,
Interrupted,
Expand Down Expand Up @@ -417,8 +418,8 @@ impl NotBefore {
///
/// This enum does not provide access to the trait features. It is only intended for backends to
/// use in constant assertions to ensure that the correct features are enabled.
#[non_exhaustive]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum Client {
AttestationClient,
CertificateClient,
Expand Down Expand Up @@ -611,6 +612,7 @@ impl Mechanism {
}

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
#[non_exhaustive]
pub enum KeySerialization {
// Asn1Der,
Cose,
Expand All @@ -627,6 +629,7 @@ pub enum KeySerialization {
}

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
#[non_exhaustive]
pub enum SignatureSerialization {
Asn1Der,
// Cose,
Expand Down
6 changes: 6 additions & 0 deletions src/mechanisms/p256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ impl Sign for super::P256 {
SignatureSerialization::Raw => {
Signature::from_slice(&signature.to_untagged_bytes()).unwrap()
}
_ => {
return Err(Error::InvalidSerializationFormat);
}
};

// return signature
Expand Down Expand Up @@ -304,6 +307,9 @@ impl Sign for super::P256Prehashed {
SignatureSerialization::Raw => {
Signature::from_slice(&signature.to_untagged_bytes()).unwrap()
}
_ => {
return Err(Error::InvalidSerializationFormat);
}
};

// return signature
Expand Down
6 changes: 6 additions & 0 deletions src/mechanisms/p384.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ impl Sign for P384 {
Signature::from_slice(der.as_bytes()).unwrap()
}
SignatureSerialization::Raw => Signature::from_slice(&signature.to_bytes()).unwrap(),
_ => {
return Err(Error::InvalidSerializationFormat);
}
};

// return signature
Expand All @@ -235,6 +238,9 @@ impl Sign for P384Prehashed {
Signature::from_slice(der.as_bytes()).unwrap()
}
SignatureSerialization::Raw => Signature::from_slice(&signature.to_bytes()).unwrap(),
_ => {
return Err(Error::InvalidSerializationFormat);
}
};

// return signature
Expand Down
6 changes: 6 additions & 0 deletions src/mechanisms/p521.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ impl Sign for P521 {
Signature::from_slice(der.as_bytes()).unwrap()
}
SignatureSerialization::Raw => Signature::from_slice(&signature.to_bytes()).unwrap(),
_ => {
return Err(Error::InvalidSerializationFormat);
}
};

// return signature
Expand All @@ -238,6 +241,9 @@ impl Sign for P521Prehashed {
Signature::from_slice(der.as_bytes()).unwrap()
}
SignatureSerialization::Raw => Signature::from_slice(&signature.to_bytes()).unwrap(),
_ => {
return Err(Error::InvalidSerializationFormat);
}
};

// return signature
Expand Down
Loading