@@ -117,3 +117,66 @@ impl KeyRestriction for AsymmetricRestriction {
117
117
impl RestrictableKeyType for Asymmetric {
118
118
type Restriction = AsymmetricRestriction ;
119
119
}
120
+
121
+ #[ cfg( test) ]
122
+ mod tests {
123
+ use crate :: keytypes:: { AsymmetricRestriction , User } ;
124
+ use crate :: tests:: utils;
125
+ use crate :: KeyRestriction ;
126
+
127
+ #[ test]
128
+ fn test_restriction_str ( ) {
129
+ let mut keyring = utils:: new_test_keyring ( ) ;
130
+ let description = & b"description" [ ..] ;
131
+ let key = keyring
132
+ . add_key :: < User , _ , _ > ( "test_restriction_str" , description)
133
+ . unwrap ( ) ;
134
+
135
+ let cases = [
136
+ (
137
+ AsymmetricRestriction :: BuiltinTrusted ,
138
+ "builtin_trusted" . into ( ) ,
139
+ ) ,
140
+ (
141
+ AsymmetricRestriction :: BuiltinAndSecondaryTrusted ,
142
+ "builtin_and_secondary_trusted" . into ( ) ,
143
+ ) ,
144
+ (
145
+ AsymmetricRestriction :: Key {
146
+ key : key. clone ( ) ,
147
+ chained : false ,
148
+ } ,
149
+ format ! ( "key_or_keyring:{}" , key. serial( ) ) ,
150
+ ) ,
151
+ (
152
+ AsymmetricRestriction :: Key {
153
+ key : key. clone ( ) ,
154
+ chained : true ,
155
+ } ,
156
+ format ! ( "key_or_keyring:{}:chain" , key. serial( ) ) ,
157
+ ) ,
158
+ (
159
+ AsymmetricRestriction :: Keyring {
160
+ keyring : keyring. clone ( ) ,
161
+ chained : false ,
162
+ } ,
163
+ format ! ( "key_or_keyring:{}" , keyring. serial( ) ) ,
164
+ ) ,
165
+ (
166
+ AsymmetricRestriction :: Keyring {
167
+ keyring : keyring. clone ( ) ,
168
+ chained : true ,
169
+ } ,
170
+ format ! ( "key_or_keyring:{}:chain" , keyring. serial( ) ) ,
171
+ ) ,
172
+ (
173
+ AsymmetricRestriction :: Chained ,
174
+ "key_or_keyring:0:chain" . into ( ) ,
175
+ ) ,
176
+ ] ;
177
+
178
+ for ( restriction, expected) in cases. iter ( ) {
179
+ assert_eq ! ( restriction. restriction( ) , expected. as_ref( ) ) ;
180
+ }
181
+ }
182
+ }
0 commit comments