55 html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg" ,
66 html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg"
77) ]
8- #![ forbid( unsafe_code) ]
9- #![ warn(
10- clippy:: cast_lossless,
11- clippy:: cast_possible_truncation,
12- clippy:: cast_possible_wrap,
13- clippy:: cast_precision_loss,
14- clippy:: cast_sign_loss,
15- clippy:: checked_conversions,
16- clippy:: implicit_saturating_sub,
17- clippy:: panic,
18- clippy:: panic_in_result_fn,
19- clippy:: unwrap_used,
20- missing_docs,
21- rust_2018_idioms,
22- unused_lifetimes,
23- unused_qualifications,
24- unreachable_pub
25- ) ]
8+ #![ allow( clippy:: missing_errors_doc, reason = "TODO" ) ]
269
2710//! ## `serde` support
2811//!
29- //! When the `serde` feature of this crate is enabled, `Serialize` and
30- //! `Deserialize` impls are provided for the [`Signature`] and [`VerifyingKey`]
31- //! types.
12+ //! When the `serde` feature of this crate is enabled, `Serialize` and `Deserialize` impls are
13+ //! provided for the [`Signature`] and [`VerifyingKey`] types.
3214//!
3315//! Please see type-specific documentation for more information.
3416//!
3517//! ## Interop
3618//!
37- //! Any crates which provide an implementation of ECDSA for a particular
38- //! elliptic curve can leverage the types from this crate, along with the
39- //! [`k256`], [`p256`], and/or [`p384`] crates to expose ECDSA functionality in
40- //! a generic, interoperable way by leveraging the [`Signature`] type with in
41- //! conjunction with the [`signature::Signer`] and [`signature::Verifier`]
42- //! traits.
19+ //! Any crates which provide an implementation of ECDSA for a particular elliptic curve can leverage
20+ //! the types from this crate, along with the [`k256`], [`p256`], and/or [`p384`] crates to expose
21+ //! ECDSA functionality in a generic, interoperable way by leveraging the [`Signature`] type with in
22+ //! conjunction with the [`signature::Signer`] and [`signature::Verifier`] traits.
4323//!
44- //! For example, the [`ring-compat`] crate implements the [`signature::Signer`]
45- //! and [`signature::Verifier`] traits in conjunction with the
46- //! [`p256::ecdsa::Signature`] and [`p384::ecdsa::Signature`] types to
47- //! wrap the ECDSA implementations from [*ring*] in a generic, interoperable
48- //! API.
24+ //! For example, the [`ring-compat`] crate implements the [`signature::Signer`] and
25+ //! [`signature::Verifier`] traits in conjunction with the [`p256::ecdsa::Signature`] and
26+ //! [`p384::ecdsa::Signature`] types to wrap the ECDSA implementations from [*ring*] in a generic,
27+ //! interoperable API.
4928//!
5029//! [`k256`]: https://docs.rs/k256
5130//! [`p256`]: https://docs.rs/p256
@@ -188,21 +167,19 @@ pub type SignatureBytes<C> = Array<u8, SignatureSize<C>>;
188167///
189168/// Both `r` and `s` MUST be non-zero.
190169///
191- /// For example, in a curve with a 256-bit modulus like NIST P-256 or
192- /// secp256k1, `r` and `s` will both be 32-bytes and serialized as big endian,
193- /// resulting in a signature with a total of 64-bytes.
170+ /// For example, in a curve with a 256-bit modulus like NIST P-256 or secp256k1, `r` and `s` are
171+ /// both 32-bytes and serialized as big endian, resulting in a signature with a total of 64-bytes.
194172///
195- /// ASN.1 DER-encoded signatures also supported via the
196- /// [`Signature::from_der`] and [`Signature:: to_der`] methods.
173+ /// ASN.1 DER-encoded signatures also supported via the [`Signature::from_der`] and
174+ /// [`Signature::to_der`] methods.
197175///
198176/// # `serde` support
199177///
200- /// When the `serde` feature of this crate is enabled, it provides support for
201- /// serializing and deserializing ECDSA signatures using the `Serialize` and
202- /// `Deserialize` traits.
178+ /// When the `serde` feature of this crate is enabled, it provides support for serializing and
179+ /// deserializing ECDSA signatures using the `Serialize` and `Deserialize` traits.
203180///
204- /// The serialization uses a hexadecimal encoding when used with
205- /// "human readable" text formats, and a binary encoding otherwise.
181+ /// The serialization uses a hexadecimal encoding when used with "human readable" text formats, and
182+ /// a binary encoding otherwise.
206183///
207184/// [IEEE P1363]: https://en.wikipedia.org/wiki/IEEE_P1363
208185#[ derive( Clone , Copy , Eq , PartialEq ) ]
@@ -218,11 +195,9 @@ where
218195 /// Parse a signature from fixed-width bytes, i.e. 2 * the size of
219196 /// [`FieldBytes`] for a particular curve.
220197 ///
221- /// # Returns
222- /// - `Ok(signature)` if the `r` and `s` components are both in the valid
223- /// range `1..n` when serialized as concatenated big endian integers.
224- /// - `Err(err)` if the `r` and/or `s` component of the signature is
225- /// out-of-range when interpreted as a big endian integer.
198+ /// # Errors
199+ /// If the `r` and/or `s` component of the signature is out-of-range when interpreted as a big
200+ /// endian integer.
226201 pub fn from_bytes ( bytes : & SignatureBytes < C > ) -> Result < Self > {
227202 let chunks = FieldBytes :: < C > :: slice_as_chunks ( bytes) . 0 ;
228203 let r = chunks[ 0 ] ;
@@ -250,11 +225,8 @@ where
250225 /// Create a [`Signature`] from the serialized `r` and `s` scalar values
251226 /// which comprise the signature.
252227 ///
253- /// # Returns
254- /// - `Ok(signature)` if the `r` and `s` components are both in the valid
255- /// range `1..n` when serialized as concatenated big endian integers.
256- /// - `Err(err)` if the `r` and/or `s` component of the signature is
257- /// out-of-range when interpreted as a big endian integer.
228+ /// # Errors
229+ /// If the `r` and/or `s` component of the signature is out-of-range when interpreted as a big endian integer.
258230 pub fn from_scalars ( r : impl Into < FieldBytes < C > > , s : impl Into < FieldBytes < C > > ) -> Result < Self > {
259231 let r = ScalarValue :: from_slice ( & r. into ( ) ) . map_err ( |_| Error :: new ( ) ) ?;
260232 let s = ScalarValue :: from_slice ( & s. into ( ) ) . map_err ( |_| Error :: new ( ) ) ?;
@@ -282,6 +254,7 @@ where
282254
283255 /// Serialize this signature as ASN.1 DER.
284256 #[ cfg( feature = "der" ) ]
257+ #[ allow( clippy:: missing_panics_doc, reason = "should not panic in practice" ) ]
285258 pub fn to_der ( & self ) -> der:: Signature < C >
286259 where
287260 der:: MaxSize < C > : ArraySize ,
@@ -321,6 +294,7 @@ where
321294 /// Normalize signature into "low S" form described in [BIP 0062: Dealing with Malleability][1].
322295 ///
323296 /// [1]: https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki
297+ #[ must_use]
324298 pub fn normalize_s ( & self ) -> Self {
325299 let mut result = * self ;
326300 let s_inv = ScalarValue :: from ( -self . s ( ) ) ;
@@ -439,11 +413,10 @@ where
439413 }
440414}
441415
442- /// ECDSA [`ObjectIdentifier`] which identifies the digest used by default
443- /// with the `Signer` and `Verifier` traits.
416+ /// ECDSA [`ObjectIdentifier`] which identifies the digest used by default with the `Signer` and
417+ /// `Verifier` traits.
444418///
445- /// To support non-default digest algorithms, use the [`SignatureWithOid`]
446- /// type instead.
419+ /// To support non-default digest algorithms, use the [`SignatureWithOid`] type instead.
447420#[ cfg( feature = "digest" ) ]
448421impl < C > AssociatedOid for Signature < C >
449422where
@@ -507,9 +480,8 @@ impl<C: EcdsaCurve> Zeroize for Signature<C> {
507480 }
508481}
509482
510- /// An extended [`Signature`] type which is parameterized by an
511- /// `ObjectIdentifier` which identifies the ECDSA variant used by a
512- /// particular signature.
483+ /// An extended [`Signature`] type which is parameterized by an `ObjectIdentifier` which identifies
484+ /// the ECDSA variant used by a particular signature.
513485///
514486/// Valid `ObjectIdentifiers` are defined in [RFC5758 § 3.2]:
515487///
@@ -540,8 +512,7 @@ where
540512{
541513 /// Create a new signature with an explicitly provided OID.
542514 ///
543- /// OID must begin with `1.2.840.10045.4`, the [RFC5758] OID prefix for
544- /// ECDSA variants.
515+ /// OID must begin with `1.2.840.10045.4`, the [RFC5758] OID prefix for ECDSA variants.
545516 ///
546517 /// [RFC5758]: https://www.rfc-editor.org/rfc/rfc5758#section-3.2
547518 pub fn new ( signature : Signature < C > , oid : ObjectIdentifier ) -> Result < Self > {
0 commit comments