Skip to content

Commit

Permalink
Add lints for all crates (#1222)
Browse files Browse the repository at this point in the history
* Add missing documentation lints

* Remove allow deprecated due to identity-diff

* Add lints to jose, document errors

* Remove commented comm reexport

* Address lints in JOSE crate

* Fix broken intra doc link
  • Loading branch information
PhilippGackstatter authored Aug 25, 2023
1 parent ce0fb8f commit 93437fc
Show file tree
Hide file tree
Showing 32 changed files with 113 additions and 221 deletions.
1 change: 0 additions & 1 deletion identity_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

#![forbid(unsafe_code)]
#![allow(deprecated)]
#![doc = include_str!("./../README.md")]
#![allow(clippy::upper_case_acronyms)]
#![warn(
Expand Down
1 change: 0 additions & 1 deletion identity_did/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

#![forbid(unsafe_code)]
#![allow(deprecated)]
#![doc = include_str!("./../README.md")]
#![allow(clippy::upper_case_acronyms)]
#![warn(
Expand Down
1 change: 0 additions & 1 deletion identity_document/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: Apache-2.0

#![forbid(unsafe_code)]
#![allow(deprecated)]
#![doc = include_str!("./../README.md")]
#![allow(clippy::upper_case_acronyms)]
#![warn(
Expand Down
13 changes: 0 additions & 13 deletions identity_iota/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#![cfg_attr(docsrs, feature(doc_cfg))]
#![forbid(unsafe_code)]
#![allow(deprecated)]
#![doc = include_str!("./../README.md")]
#![allow(clippy::upper_case_acronyms)]
#![warn(
Expand Down Expand Up @@ -70,18 +69,6 @@ pub mod iota {
pub use identity_iota_core::*;
}

// #[cfg(feature = "comm")]
// #[cfg_attr(docsrs, doc(cfg(feature = "comm")))]
// pub mod comm {
// //! DID Communications Message Specification
// //!
// //! [Specification](https://github.com/iotaledger/identity.rs/tree/main/docs/DID%20Communications%20Research%20and%20Specification)

// pub use identity_comm::envelope::*;
// pub use identity_comm::error::*;
// pub use identity_comm::message::*;
// }

pub mod prelude {
//! Prelude of commonly used types

Expand Down
17 changes: 13 additions & 4 deletions identity_jose/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,43 @@ pub type Result<T, E = Error> = core::result::Result<T, E>;
/// All possible errors that can occur in the library.
#[derive(Debug, thiserror::Error)]
pub enum Error {
/// Caused by invalid json serialization or deserialization.
#[error("invalid json")]
InvalidJson(#[source] serde_json::Error),
/// Caused by invalid base64 encoded data.
#[error("invalid base64")]
InvalidBase64(#[source] identity_core::error::Error),
/// Caused by bytes not being valid utf-8.
#[error("invalid utf-8")]
InvalidUtf8(#[source] core::str::Utf8Error),
/// Caused by a claim not being of an expected value.
#[error("invalid claim `{0}`")]
InvalidClaim(&'static str),
/// Caused by a missing claim.
#[error("missing claim `{0}`")]
MissingClaim(&'static str),
/// Caused by an parameter with an invalid value.
#[error("invalid param: {0}")]
InvalidParam(&'static str),
/// Caused by a missing parameter.
#[error("missing param `{0}`")]
MissingParam(&'static str),
/// Caused by invalid content of a JSON Web Signature.
#[error("{0}")]
InvalidContent(&'static str),
/// Caused by an invalid key format.
#[error("invalid key format for type `{0}`")]
KeyError(&'static str),
#[error("mismatch between header and jwk alg values")]
AlgorithmMismatch,
/// Caused by a string that does not correspond to a supported [`JwsAlgorithm`](crate::jws::JwsAlgorithm).
#[error("attempt to parse an unregistered jws algorithm")]
JwsAlgorithmParsingError,
#[error("signature creation error")]
SignatureCreationError(#[source] Box<dyn std::error::Error + Send + Sync>),
/// Caused by an error during signature verification.
#[error("signature verification error")]
SignatureVerificationError(#[source] crate::jws::SignatureVerificationError),
/// Caused by a mising header.
#[error("missing header")]
MissingHeader(&'static str),
/// Caused by a missing `alg` claim in the protected header.
#[error("missing alg in protected header")]
ProtectedHeaderWithoutAlg,
}
2 changes: 2 additions & 0 deletions identity_jose/src/jose/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2020-2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

//! Traits for JOSE headers.

mod traits;

pub use self::traits::*;
3 changes: 3 additions & 0 deletions identity_jose/src/jose/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@

use crate::jwt::JwtHeader;

/// An abstraction over different JOSE headers.
pub trait JoseHeader {
/// Returns the header common to all [`JoseHeader`]s.
fn common(&self) -> &JwtHeader;

/// Returns `true` if the header has the given `claim`, `false` otherwise.
fn has_claim(&self, claim: &str) -> bool;
}

Expand Down
1 change: 1 addition & 0 deletions identity_jose/src/jwk/curve/ec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub enum EcCurve {
}

impl EcCurve {
/// Returns the name of the curve as a string slice.
pub const fn name(self) -> &'static str {
match self {
Self::P256 => "P-256",
Expand Down
42 changes: 0 additions & 42 deletions identity_jose/src/jwk/curve/ecdh.rs

This file was deleted.

1 change: 1 addition & 0 deletions identity_jose/src/jwk/curve/ecx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub enum EcxCurve {
}

impl EcxCurve {
/// Returns the name of the curve as a string slice.
pub const fn name(self) -> &'static str {
match self {
Self::X25519 => "X25519",
Expand Down
1 change: 1 addition & 0 deletions identity_jose/src/jwk/curve/ed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub enum EdCurve {
}

impl EdCurve {
/// Returns the name of the curve as a string slice.
pub const fn name(self) -> &'static str {
match self {
Self::Ed25519 => "Ed25519",
Expand Down
2 changes: 0 additions & 2 deletions identity_jose/src/jwk/curve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

mod ec;
mod ecdh;
mod ecx;
mod ed;

pub use self::ec::*;
pub use self::ecdh::*;
pub use self::ecx::*;
pub use self::ed::*;
4 changes: 4 additions & 0 deletions identity_jose/src/jwk/key_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ use crate::jwk::JwkType;
#[derive(Zeroize)]
#[zeroize(drop)]
pub enum JwkParams {
/// Elliptic Curve parameters.
Ec(JwkParamsEc),
/// RSA parameters.
Rsa(JwkParamsRsa),
/// Octet Sequence parameters used to represent symmetric keys.
Oct(JwkParamsOct),
/// Octet Key Pairs parameters.
Okp(JwkParamsOkp),
}

Expand Down
1 change: 1 addition & 0 deletions identity_jose/src/jwk/key_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ impl JwkSet {
&self.keys
}

/// Returns an iterator over the contained [`Jwk`]s.
pub fn iter(&self) -> Iter<'_, Jwk> {
self.keys.iter()
}
Expand Down
1 change: 1 addition & 0 deletions identity_jose/src/jws/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub enum JwsAlgorithm {
}

impl JwsAlgorithm {
/// A slice of all supported [`JwsAlgorithm`]s.
pub const ALL: &'static [Self] = &[
Self::HS256,
Self::HS384,
Expand Down
3 changes: 3 additions & 0 deletions identity_jose/src/jws/charset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use core::str::from_utf8;
use crate::error::Error;
use crate::error::Result;

/// The requirements towards the character set when encoding a JWS.
///
/// See the individual variants for more details.
#[derive(Clone, Copy, Debug)]
pub enum CharSet {
/// The ASCII space character and all printable ASCII characters other
Expand Down
3 changes: 3 additions & 0 deletions identity_jose/src/jws/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ use super::VerificationInput;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct DecodedJws<'a> {
/// The decoded protected header.
pub protected: JwsHeader,
/// The decoded unprotected header.
pub unprotected: Option<Box<JwsHeader>>,
/// The decoded raw claims.
pub claims: Cow<'a, [u8]>,
}

Expand Down
13 changes: 9 additions & 4 deletions identity_jose/src/jws/encoding/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ pub struct CompactJwsEncoder<'a> {
/// Options determining whether the payload is detached and if not
/// which additional requirements the payload must satisfy.
pub enum CompactJwsEncodingOptions {
NonDetached { charset_requirements: CharSet },
/// Includes the payload in the JWS, i.e. non-detached mode.
NonDetached {
/// The requirements towards the character set when encoding a JWS.
charset_requirements: CharSet,
},
/// Does not include the payload in the JWS, i.e. detached mode.
Detached,
}

Expand Down Expand Up @@ -63,7 +68,7 @@ impl<'payload> CompactJwsEncoder<'payload> {
) -> Result<Self> {
Self::validate_header(protected_header)?;
let encoded_protected_header: String = jwu::encode_b64_json(protected_header)?;
let maybe_encoded: MaybeEncodedPayload = MaybeEncodedPayload::encode_if_b64(payload, Some(protected_header));
let maybe_encoded: MaybeEncodedPayload<'_> = MaybeEncodedPayload::encode_if_b64(payload, Some(protected_header));
let signing_input: Box<[u8]> =
jwu::create_message(encoded_protected_header.as_bytes(), maybe_encoded.as_bytes()).into();

Expand Down Expand Up @@ -128,7 +133,7 @@ impl<'payload, 'unprotected> FlattenedJwsEncoder<'payload, 'unprotected> {
/// [`Self::into_jws`](CompactJwsEncoder::into_jws()) for information on how to proceed.
pub fn new(payload: &'payload [u8], recipient: Recipient<'unprotected>, detached: bool) -> Result<Self> {
utils::validate_headers_json_serialization(recipient)?;
let maybe_encoded: MaybeEncodedPayload = MaybeEncodedPayload::encode_if_b64(payload, recipient.protected);
let maybe_encoded: MaybeEncodedPayload<'_> = MaybeEncodedPayload::encode_if_b64(payload, recipient.protected);
let signing_data: SigningData = SigningData::new(maybe_encoded.as_bytes(), recipient.protected)?;
let processed_payload: Option<Cow<'payload, str>> = if !detached {
// The only additional validation required when processing the payload to be used with the flattened JWS Json
Expand Down Expand Up @@ -266,7 +271,7 @@ impl<'payload, 'unprotected> GeneralJwsEncoder<'payload, 'unprotected> {
detached,
..
} = self;
let general: General = {
let general: General<'_, '_> = {
if detached {
General {
payload: None,
Expand Down
1 change: 1 addition & 0 deletions identity_jose/src/jws/recipient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl<'a> Default for Recipient<'a> {
}

impl<'a> Recipient<'a> {
/// Creates a new recipient with no header set.
pub fn new() -> Self {
Self {
protected: None,
Expand Down
Loading

0 comments on commit 93437fc

Please sign in to comment.