From 0dcc59c2b9ec411277c6c796cff2daeb954cfee2 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Tue, 5 May 2020 15:59:07 +0300 Subject: [PATCH] Add doctest to Secp256k1::verify --- src/lib.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index a60a2b5..92c9a91 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -667,6 +667,29 @@ impl Secp256k1 { /// be used for Bitcoin consensus checking since there may exist signatures /// which OpenSSL would verify but not libsecp256k1, or vice-versa. Requires a /// 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] pub fn verify(&self, msg: &Message, sig: &Signature, pk: &key::PublicKey) -> Result<(), Error> { unsafe {