Skip to content

Commit 9925d25

Browse files
committed
Add PKey sign test case
Signed-off-by: Patrick Uiterwijk <patrick@puiterwijk.org>
1 parent 6dfa5e9 commit 9925d25

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed

src/tests/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ mod keytype;
3737
mod link;
3838
mod newring;
3939
mod permitting;
40+
mod pkey;
4041
mod reading;
4142
mod revoke;
4243
mod search;

src/tests/pkey.rs

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// Copyright (c) 2020, Patrick Uiterwijk
2+
// Copyright (c) 2019, Ben Boeckel
3+
// All rights reserved.
4+
//
5+
// Redistribution and use in source and binary forms, with or without modification,
6+
// are permitted provided that the following conditions are met:
7+
//
8+
// * Redistributions of source code must retain the above copyright notice,
9+
// this list of conditions and the following disclaimer.
10+
// * Redistributions in binary form must reproduce the above copyright notice,
11+
// this list of conditions and the following disclaimer in the documentation
12+
// and/or other materials provided with the distribution.
13+
// * Neither the name of this project nor the names of its contributors
14+
// may be used to endorse or promote products derived from this software
15+
// without specific prior written permission.
16+
//
17+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21+
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
28+
use crate::{keytypes::Asymmetric, KeyctlEncoding, KeyctlHash, PublicKeyOptions};
29+
30+
use super::utils;
31+
32+
#[test]
33+
fn sign() {
34+
let mut keyring = utils::new_test_keyring();
35+
let payload = vec![
36+
48, 130, 4, 190, 2, 1, 0, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1, 5, 0, 4, 130,
37+
4, 168, 48, 130, 4, 164, 2, 1, 0, 2, 130, 1, 1, 0, 167, 196, 151, 59, 20, 105, 57, 38, 72,
38+
54, 27, 47, 14, 114, 18, 189, 217, 38, 29, 41, 182, 1, 17, 246, 124, 231, 240, 13, 150, 42,
39+
193, 68, 227, 63, 77, 206, 92, 201, 157, 141, 103, 142, 245, 158, 43, 136, 213, 58, 88, 31,
40+
44, 195, 58, 61, 172, 191, 143, 161, 71, 248, 11, 149, 37, 122, 103, 145, 84, 10, 243, 3,
41+
42, 219, 61, 141, 195, 46, 255, 143, 182, 238, 108, 206, 38, 126, 148, 112, 60, 245, 3, 27,
42+
210, 182, 202, 135, 35, 53, 161, 216, 229, 76, 93, 100, 142, 58, 111, 183, 142, 134, 95,
43+
167, 99, 220, 5, 181, 47, 93, 23, 247, 35, 127, 119, 31, 55, 125, 237, 58, 91, 20, 48, 249,
44+
214, 88, 175, 128, 138, 130, 119, 209, 204, 138, 165, 175, 250, 99, 210, 235, 55, 151, 81,
45+
227, 226, 14, 234, 125, 137, 113, 113, 132, 153, 63, 139, 97, 189, 193, 10, 131, 38, 23,
46+
131, 173, 75, 235, 165, 250, 83, 159, 42, 139, 118, 9, 50, 194, 110, 69, 21, 92, 113, 202,
47+
120, 161, 219, 120, 155, 130, 57, 22, 128, 25, 28, 86, 226, 157, 144, 194, 224, 240, 230,
48+
155, 232, 157, 8, 117, 158, 98, 101, 82, 82, 89, 132, 205, 149, 69, 185, 188, 130, 167, 91,
49+
72, 195, 254, 58, 0, 124, 203, 169, 24, 122, 111, 64, 100, 82, 21, 58, 49, 161, 221, 229,
50+
179, 250, 61, 41, 234, 190, 48, 209, 7, 2, 3, 1, 0, 1, 2, 130, 1, 1, 0, 151, 112, 223, 175,
51+
6, 10, 193, 250, 235, 158, 99, 197, 131, 125, 183, 171, 70, 84, 160, 104, 161, 145, 175,
52+
188, 88, 30, 42, 84, 169, 100, 104, 216, 29, 102, 108, 126, 198, 197, 124, 130, 67, 164, 9,
53+
213, 192, 168, 161, 10, 44, 183, 223, 121, 79, 158, 146, 204, 205, 3, 162, 106, 167, 81,
54+
247, 229, 217, 141, 151, 86, 214, 236, 218, 7, 212, 53, 158, 166, 83, 45, 80, 205, 66, 204,
55+
136, 117, 36, 219, 120, 59, 23, 150, 75, 12, 148, 31, 142, 202, 0, 18, 65, 82, 64, 207,
56+
223, 143, 162, 127, 8, 154, 5, 200, 157, 92, 228, 142, 28, 118, 37, 135, 2, 181, 50, 59,
57+
172, 164, 240, 187, 7, 176, 232, 200, 222, 49, 79, 99, 104, 140, 122, 90, 187, 75, 69, 219,
58+
107, 210, 110, 30, 77, 163, 32, 54, 144, 48, 228, 161, 156, 19, 159, 80, 61, 195, 55, 81,
59+
108, 171, 61, 132, 170, 3, 13, 22, 62, 117, 65, 40, 94, 218, 78, 239, 140, 170, 79, 138,
60+
201, 117, 219, 166, 89, 224, 127, 244, 112, 78, 163, 80, 50, 135, 70, 15, 108, 24, 172,
61+
189, 213, 94, 14, 5, 17, 208, 54, 155, 2, 6, 254, 127, 73, 242, 140, 180, 40, 2, 16, 243,
62+
75, 75, 132, 158, 111, 21, 36, 163, 15, 33, 178, 127, 17, 254, 118, 245, 105, 229, 153,
63+
253, 95, 60, 26, 242, 37, 167, 92, 21, 17, 151, 197, 200, 174, 49, 2, 129, 129, 0, 216,
64+
209, 46, 177, 19, 142, 77, 138, 123, 145, 129, 179, 223, 133, 64, 238, 65, 113, 19, 182,
65+
176, 96, 201, 37, 78, 167, 47, 80, 59, 148, 77, 189, 184, 81, 85, 69, 11, 16, 69, 88, 84,
66+
47, 24, 11, 190, 162, 235, 144, 138, 85, 113, 25, 70, 3, 128, 200, 31, 210, 202, 70, 18,
67+
209, 9, 42, 208, 142, 201, 220, 97, 24, 31, 119, 221, 188, 65, 20, 152, 125, 214, 128, 199,
68+
243, 161, 147, 236, 102, 84, 222, 99, 226, 60, 219, 59, 154, 154, 141, 192, 223, 158, 197,
69+
112, 10, 240, 227, 180, 76, 162, 96, 85, 24, 183, 79, 10, 159, 70, 232, 248, 13, 105, 164,
70+
190, 33, 74, 29, 228, 157, 89, 217, 2, 129, 129, 0, 198, 22, 50, 239, 252, 68, 241, 51,
71+
189, 227, 163, 35, 79, 142, 108, 73, 84, 144, 4, 12, 84, 47, 40, 148, 109, 26, 185, 154,
72+
55, 221, 106, 29, 218, 182, 71, 92, 52, 70, 239, 157, 225, 204, 137, 171, 150, 136, 223,
73+
61, 217, 205, 207, 122, 99, 183, 104, 35, 144, 154, 31, 50, 212, 20, 152, 73, 130, 167,
74+
178, 201, 151, 69, 36, 117, 3, 108, 135, 132, 70, 169, 103, 248, 147, 145, 134, 122, 206,
75+
124, 202, 159, 162, 119, 106, 155, 137, 37, 112, 238, 78, 99, 89, 31, 250, 105, 176, 213,
76+
198, 1, 49, 188, 34, 198, 219, 38, 148, 140, 57, 245, 188, 243, 250, 161, 167, 186, 62, 27,
77+
47, 142, 213, 223, 2, 129, 128, 30, 66, 219, 236, 117, 25, 72, 115, 74, 153, 221, 107, 120,
78+
136, 5, 174, 251, 77, 71, 254, 24, 145, 249, 161, 14, 96, 65, 55, 70, 137, 133, 108, 52,
79+
92, 141, 181, 44, 61, 34, 32, 152, 231, 85, 200, 213, 219, 177, 91, 36, 35, 150, 188, 123,
80+
76, 35, 222, 74, 170, 197, 246, 143, 203, 195, 38, 201, 163, 20, 67, 128, 253, 183, 238,
81+
167, 241, 13, 120, 77, 108, 74, 211, 0, 149, 93, 120, 226, 230, 201, 115, 156, 167, 71,
82+
237, 37, 93, 135, 178, 191, 55, 182, 214, 65, 180, 21, 57, 2, 194, 43, 107, 156, 148, 237,
83+
136, 199, 167, 193, 98, 228, 180, 34, 137, 142, 203, 224, 167, 89, 112, 40, 201, 2, 129,
84+
128, 56, 100, 229, 135, 145, 72, 135, 106, 245, 170, 179, 45, 64, 95, 9, 209, 46, 179, 249,
85+
147, 16, 252, 132, 15, 13, 168, 200, 34, 113, 185, 37, 150, 238, 71, 106, 181, 131, 100,
86+
150, 159, 90, 67, 131, 6, 72, 203, 26, 211, 95, 8, 203, 2, 203, 20, 210, 31, 29, 241, 226,
87+
227, 243, 161, 17, 98, 12, 66, 118, 18, 18, 112, 234, 218, 45, 105, 94, 131, 120, 34, 142,
88+
169, 36, 74, 16, 1, 50, 124, 48, 171, 149, 243, 109, 116, 110, 109, 44, 99, 140, 9, 152,
89+
188, 19, 236, 183, 29, 133, 75, 157, 191, 52, 31, 109, 16, 228, 197, 175, 82, 152, 194,
90+
213, 29, 228, 196, 143, 29, 234, 66, 61, 253, 2, 129, 129, 0, 174, 243, 86, 92, 83, 244,
91+
47, 48, 26, 177, 77, 189, 162, 233, 196, 12, 241, 209, 234, 92, 189, 29, 255, 0, 140, 104,
92+
76, 29, 218, 187, 103, 183, 64, 133, 125, 215, 105, 227, 165, 52, 166, 41, 205, 194, 91,
93+
136, 165, 90, 193, 56, 204, 117, 105, 216, 157, 227, 24, 14, 170, 253, 56, 61, 2, 152, 212,
94+
209, 77, 21, 134, 245, 82, 196, 10, 27, 71, 61, 206, 195, 222, 20, 5, 34, 34, 242, 39, 93,
95+
86, 246, 23, 29, 68, 136, 48, 27, 230, 145, 155, 7, 222, 10, 241, 244, 174, 49, 150, 153,
96+
228, 46, 238, 189, 140, 64, 31, 207, 79, 194, 229, 239, 105, 237, 72, 118, 144, 247, 237,
97+
146, 96, 192,
98+
];
99+
let key = keyring
100+
.add_key::<Asymmetric, _, _>("sign_key", payload)
101+
.unwrap();
102+
103+
let digest = vec![0x1, 0x2, 0x3, 0x4];
104+
let options = PublicKeyOptions {
105+
encoding: Some(KeyctlEncoding::RsassaPkcs1V15),
106+
hash: Some(KeyctlHash::Sha256),
107+
};
108+
109+
let signature = key.sign(&options, &digest).unwrap();
110+
assert!(!signature.is_empty());
111+
}

0 commit comments

Comments
 (0)