@@ -48,8 +48,7 @@ func validGenerateBody() []byte {
4848 KemID : KemAlgorithmDHKEMX25519HKDFSHA256 ,
4949 },
5050 },
51- KeyProtectionMechanism : KeyProtectionMechanismVMEmulated ,
52- Lifespan : ProtoDuration {Seconds : 3600 },
51+ Lifespan : ProtoDuration {Seconds : 3600 },
5352 })
5453 return body
5554}
@@ -141,23 +140,19 @@ func TestHandleGenerateKeyBadRequest(t *testing.T) {
141140 }{
142141 {
143142 name : "unsupported algorithm type" ,
144- body : GenerateKeyRequest {Algorithm : AlgorithmDetails {Type : "mac" , Params : AlgorithmParams {KemID : KemAlgorithmDHKEMX25519HKDFSHA256 }}, KeyProtectionMechanism : KeyProtectionMechanismVMEmulated , Lifespan : ProtoDuration {Seconds : 3600 }},
143+ body : GenerateKeyRequest {Algorithm : AlgorithmDetails {Type : "mac" , Params : AlgorithmParams {KemID : KemAlgorithmDHKEMX25519HKDFSHA256 }}, Lifespan : ProtoDuration {Seconds : 3600 }},
145144 },
146145 {
147146 name : "unsupported algorithm" ,
148- body : GenerateKeyRequest {Algorithm : AlgorithmDetails {Type : "kem" , Params : AlgorithmParams {KemID : KemAlgorithmUnspecified }}, KeyProtectionMechanism : KeyProtectionMechanismVMEmulated , Lifespan : ProtoDuration {Seconds : 3600 }},
149- },
150- {
151- name : "unsupported key protection mechanism" ,
152- body : GenerateKeyRequest {Algorithm : AlgorithmDetails {Type : "kem" , Params : AlgorithmParams {KemID : KemAlgorithmDHKEMX25519HKDFSHA256 }}, KeyProtectionMechanism : KeyProtectionMechanism (99 ), Lifespan : ProtoDuration {Seconds : 3600 }},
147+ body : GenerateKeyRequest {Algorithm : AlgorithmDetails {Type : "kem" , Params : AlgorithmParams {KemID : KemAlgorithmUnspecified }}, Lifespan : ProtoDuration {Seconds : 3600 }},
153148 },
154149 {
155150 name : "zero lifespan" ,
156- body : GenerateKeyRequest {Algorithm : AlgorithmDetails {Type : "kem" , Params : AlgorithmParams {KemID : KemAlgorithmDHKEMX25519HKDFSHA256 }}, KeyProtectionMechanism : KeyProtectionMechanismVMEmulated , Lifespan : ProtoDuration {Seconds : 0 }},
151+ body : GenerateKeyRequest {Algorithm : AlgorithmDetails {Type : "kem" , Params : AlgorithmParams {KemID : KemAlgorithmDHKEMX25519HKDFSHA256 }}, Lifespan : ProtoDuration {Seconds : 0 }},
157152 },
158153 {
159154 name : "missing algorithm (defaults to 0, type empty)" ,
160- body : GenerateKeyRequest {KeyProtectionMechanism : KeyProtectionMechanismVMEmulated , Lifespan : ProtoDuration {Seconds : 3600 }},
155+ body : GenerateKeyRequest {Lifespan : ProtoDuration {Seconds : 3600 }},
161156 },
162157 }
163158
@@ -198,9 +193,9 @@ func TestHandleGenerateKeyBadJSON(t *testing.T) {
198193 body string
199194 }{
200195 {"not json" , "not json" },
201- {"lifespan as string" , `{"algorithm":1,"key_protection_mechanism":2," lifespan":"3600"}` },
202- {"lifespan as string with suffix" , `{"algorithm":1,"key_protection_mechanism":2," lifespan":"3600s"}` },
203- {"lifespan negative" , `{"algorithm":1,"key_protection_mechanism":2," lifespan":-1}` },
196+ {"lifespan as string" , `{"algorithm":1,"lifespan":"3600"}` },
197+ {"lifespan as string with suffix" , `{"algorithm":1,"lifespan":"3600s"}` },
198+ {"lifespan negative" , `{"algorithm":1,"lifespan":-1}` },
204199 }
205200
206201 for _ , tc := range badBodies {
@@ -246,17 +241,17 @@ func TestHandleGenerateKeyFlexibleLifespan(t *testing.T) {
246241 }{
247242 {
248243 name : "integer seconds" ,
249- body : `{"algorithm":{"type":"kem","params":{"kem_id":"DHKEM_X25519_HKDF_SHA256"}},"key_protection_mechanism":"KEY_PROTECTION_VM_EMULATED"," lifespan":3600}` ,
244+ body : `{"algorithm":{"type":"kem","params":{"kem_id":"DHKEM_X25519_HKDF_SHA256"}},"lifespan":3600}` ,
250245 expected : 3600 ,
251246 },
252247 {
253248 name : "float seconds" ,
254- body : `{"algorithm":{"type":"kem","params":{"kem_id":"DHKEM_X25519_HKDF_SHA256"}},"key_protection_mechanism":"KEY_PROTECTION_VM_EMULATED"," lifespan":1.5}` ,
249+ body : `{"algorithm":{"type":"kem","params":{"kem_id":"DHKEM_X25519_HKDF_SHA256"}},"lifespan":1.5}` ,
255250 expected : 1 , // Truncated to 1
256251 },
257252 {
258253 name : "float seconds round down" ,
259- body : `{"algorithm":{"type":"kem","params":{"kem_id":"DHKEM_X25519_HKDF_SHA256"}},"key_protection_mechanism":"KEY_PROTECTION_VM_EMULATED"," lifespan":3600.9}` ,
254+ body : `{"algorithm":{"type":"kem","params":{"kem_id":"DHKEM_X25519_HKDF_SHA256"}},"lifespan":3600.9}` ,
260255 expected : 3600 ,
261256 },
262257 }
0 commit comments