Add doctest to Secp256k1::verify

This commit is contained in:
Kirill Fomichev 2020-05-05 15:59:07 +03:00
parent 0782872fb0
commit 0dcc59c2b9
No known key found for this signature in database
GPG Key ID: 6AA0144D5E0C0C0A
1 changed files with 23 additions and 0 deletions

View File

@ -667,6 +667,29 @@ impl<C: Verification> Secp256k1<C> {
/// be used for Bitcoin consensus checking since there may exist signatures /// be used for Bitcoin consensus checking since there may exist signatures
/// which OpenSSL would verify but not libsecp256k1, or vice-versa. Requires a /// which OpenSSL would verify but not libsecp256k1, or vice-versa. Requires a
/// verify-capable context. /// verify-capable context.
///
/// ```rust
/// # extern crate secp256k1;
/// # #[cfg(feature="rand")]
/// # extern crate rand;
/// #
/// # fn main() {
/// # #[cfg(feature="rand")] {
/// # use rand::OsRng;
/// # use secp256k1::{Secp256k1, Message, Error};
/// #
/// # let secp = Secp256k1::new();
/// # let mut rng = OsRng::new().expect("OsRng");
/// # let (secret_key, public_key) = secp.generate_keypair(&mut rng);
/// #
/// let message = Message::from_slice(&[0xab; 32]).expect("32 bytes");
/// let sig = secp.sign(&message, &secret_key);
/// assert_eq!(secp.verify(&message, &sig, &public_key), Ok(()));
///
/// let message = Message::from_slice(&[0xcd; 32]).expect("32 bytes");
/// assert_eq!(secp.verify(&message, &sig, &public_key), Err(Error::IncorrectSignature));
/// # } }
/// ```
#[inline] #[inline]
pub fn verify(&self, msg: &Message, sig: &Signature, pk: &key::PublicKey) -> Result<(), Error> { pub fn verify(&self, msg: &Message, sig: &Signature, pk: &key::PublicKey) -> Result<(), Error> {
unsafe { unsafe {