tink_core/
verifier.rs

1// Copyright 2020 The Tink-Rust Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15////////////////////////////////////////////////////////////////////////////////
16
17//! Digital signature verification.
18
19/// `Verifier` is the verifying interface for digital signature.
20///
21/// Implementations of this trait are secure against adaptive chosen-message
22/// attacks.  Signing data ensures authenticity and integrity of that data, but
23/// not its secrecy.
24pub trait Verifier: VerifierBoxClone {
25    /// Returns `Ok(())` if `signature` is a valid signature for `data`; otherwise returns an error.
26    fn verify(&self, signature: &[u8], data: &[u8]) -> Result<(), crate::TinkError>;
27}
28
29/// Trait bound to indicate that primitive trait objects should support cloning
30/// themselves as trait objects.
31pub trait VerifierBoxClone {
32    fn box_clone(&self) -> Box<dyn Verifier>;
33}
34
35/// Default implementation of the box-clone trait bound for any underlying
36/// concrete type that implements [`Clone`].
37impl<T> VerifierBoxClone for T
38where
39    T: 'static + Verifier + Clone,
40{
41    fn box_clone(&self) -> Box<dyn Verifier> {
42        Box::new(self.clone())
43    }
44}