tink_core/signer.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 signing.
18
19/// `Signer` is the signing 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 Signer: SignerBoxClone {
25 /// Computes the digital signature for `data`.
26 fn sign(&self, data: &[u8]) -> Result<Vec<u8>, crate::TinkError>;
27}
28
29/// Trait bound to indicate that primitive trait objects should support cloning
30/// themselves as trait objects.
31pub trait SignerBoxClone {
32 fn box_clone(&self) -> Box<dyn Signer>;
33}
34
35/// Default implementation of the box-clone trait bound for any underlying
36/// concrete type that implements [`Clone`].
37impl<T> SignerBoxClone for T
38where
39 T: 'static + Signer + Clone,
40{
41 fn box_clone(&self) -> Box<dyn Signer> {
42 Box::new(self.clone())
43 }
44}