Skip to content

Commit 7a6f3c8

Browse files
committed
Derive Copy and Clone for ring::signature::Signature.
Derive `Copy` and `Clone` for `Signature`. Add some utilities for testing `Clone`, `Copy`, `Send`, and `Sync` and use them to test that `Signature` implements these traits.
1 parent cbcba8e commit 7a6f3c8

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ include = [
253253
"tests/rsa_pss_sign_tests.txt",
254254
"tests/rsa_pss_verify_tests.txt",
255255
"tests/rsa_tests.rs",
256+
"tests/signature_tests.rs",
256257
"third-party/NIST/README.md",
257258
"third-party/NIST/sha256sums.txt",
258259
"third-party/NIST/SHAVS/SHA1LongMsg.rsp",

src/signature_impl.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use ec;
1919

2020
/// A public key signature returned from a signing operation.
21+
#[derive(Clone, Copy)]
2122
pub struct Signature {
2223
value: [u8; MAX_LEN],
2324
len: usize,

src/test.rs

+18
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,24 @@ use std::string::String;
126126
use std::vec::Vec;
127127
use std::io::BufRead;
128128

129+
130+
/// `compile_time_assert_clone::<T>();` fails to compile if `T` doesn't
131+
/// implement `Clone`.
132+
pub fn compile_time_assert_clone<T: Clone>() {}
133+
134+
/// `compile_time_assert_copy::<T>();` fails to compile if `T` doesn't
135+
/// implement `Copy`.
136+
pub fn compile_time_assert_copy<T: Copy>() {}
137+
138+
/// `compile_time_assert_send::<T>();` fails to compile if `T` doesn't
139+
/// implement `Send`.
140+
pub fn compile_time_assert_send<T: Send>() {}
141+
142+
/// `compile_time_assert_sync::<T>();` fails to compile if `T` doesn't
143+
/// implement `Sync`.
144+
pub fn compile_time_assert_sync<T: Sync>() {}
145+
146+
129147
/// A test case. A test case consists of a set of named attributes. Every
130148
/// attribute in the test case must be consumed exactly once; this helps catch
131149
/// typos and omissions.

tests/signature_tests.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
extern crate ring;
2+
3+
use ring::signature;
4+
use ring::test;
5+
6+
#[test]
7+
fn signature_impl_test() {
8+
test::compile_time_assert_clone::<signature::Signature>();
9+
test::compile_time_assert_copy::<signature::Signature>();
10+
test::compile_time_assert_send::<signature::Signature>();
11+
test::compile_time_assert_sync::<signature::Signature>();
12+
}

0 commit comments

Comments
 (0)