Skip to content

Commit

Permalink
Merge pull request #212 from fanatid/verify-doctest
Browse files Browse the repository at this point in the history
Add doctest to Secp256k1::verify
  • Loading branch information
apoelstra committed May 13, 2020
2 parents e6a82fa + 0dcc59c commit a184212
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/lib.rs
Expand Up @@ -667,6 +667,29 @@ impl<C: Verification> Secp256k1<C> {
/// 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 {
Expand Down

0 comments on commit a184212

Please sign in to comment.