Skip to content

Commit 763e293

Browse files
committed
Align Key Generation API with contract
- Update GenerateKemRequest and GenerateKemResponse JSON tags to use snake_case. - Update KemAlgorithm enum string representation to remove KEM_ALGORITHM_ prefix. - Update tests to reflect these changes.
1 parent 962d7ae commit 763e293

File tree

3 files changed

+8
-13
lines changed

3 files changed

+8
-13
lines changed

keymanager/workload_service/proto_enums.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ const (
1919
var (
2020
kemAlgorithmToString = map[KemAlgorithm]string{
2121
KemAlgorithmUnspecified: "KEM_ALGORITHM_UNSPECIFIED",
22-
KemAlgorithmDHKEMX25519HKDFSHA256: "KEM_ALGORITHM_DHKEM_X25519_HKDF_SHA256",
22+
KemAlgorithmDHKEMX25519HKDFSHA256: "DHKEM_X25519_HKDF_SHA256",
2323
}
2424
stringToKemAlgorithm = map[string]KemAlgorithm{
25-
"KEM_ALGORITHM_UNSPECIFIED": KemAlgorithmUnspecified,
26-
"KEM_ALGORITHM_DHKEM_X25519_HKDF_SHA256": KemAlgorithmDHKEMX25519HKDFSHA256,
25+
"KEM_ALGORITHM_UNSPECIFIED": KemAlgorithmUnspecified,
26+
"DHKEM_X25519_HKDF_SHA256": KemAlgorithmDHKEMX25519HKDFSHA256,
2727
}
2828
)
2929

keymanager/workload_service/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (s *Server) handleGenerateKem(w http.ResponseWriter, r *http.Request) {
146146
http.Error(
147147
w,
148148
fmt.Sprintf(
149-
"unsupported algorithm: only KEM_ALGORITHM_DHKEM_X25519_HKDF_SHA256 (%d) is supported",
149+
"unsupported algorithm: only DHKEM_X25519_HKDF_SHA256 (%d) is supported",
150150
KemAlgorithmDHKEMX25519HKDFSHA256,
151151
),
152152
http.StatusBadRequest,

keymanager/workload_service/server_test.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func TestHandleGenerateKemBadRequest(t *testing.T) {
144144
body: GenerateKemRequest{Algorithm: KemAlgorithmDHKEMX25519HKDFSHA256, KeyProtectionMechanism: KeyProtectionMechanismVM, Lifespan: ProtoDuration{Seconds: 0}},
145145
},
146146
{
147-
name: "missing algorithm (defaults to UNSPECIFIED)",
147+
name: "missing algorithm (defaults to 0)",
148148
body: GenerateKemRequest{KeyProtectionMechanism: KeyProtectionMechanismVM, Lifespan: ProtoDuration{Seconds: 3600}},
149149
},
150150
}
@@ -175,14 +175,9 @@ func TestHandleGenerateKemBadJSON(t *testing.T) {
175175
body string
176176
}{
177177
{"not json", "not json"},
178-
{"lifespan as integer", `{"algorithm":"KEM_ALGORITHM_DHKEM_X25519_HKDF_SHA256","key_protection_mechanism":"KEY_PROTECTION_VM","lifespan":3600}`},
179-
{"lifespan missing s suffix", `{"algorithm":"KEM_ALGORITHM_DHKEM_X25519_HKDF_SHA256","key_protection_mechanism":"KEY_PROTECTION_VM","lifespan":"3600"}`},
180-
{"lifespan negative", `{"algorithm":"KEM_ALGORITHM_DHKEM_X25519_HKDF_SHA256","key_protection_mechanism":"KEY_PROTECTION_VM","lifespan":"-1s"}`},
181-
// Added tests for invalid enum strings
182-
{"invalid algorithm", `{"algorithm":"INVALID","key_protection_mechanism":"KEY_PROTECTION_VM","lifespan":"3600s"}`},
183-
{"invalid protection mechanism", `{"algorithm":"KEM_ALGORITHM_DHKEM_X25519_HKDF_SHA256","key_protection_mechanism":"INVALID","lifespan":"3600s"}`},
184-
// Test wrong type for enums (int instead of string), if we want to enforce string only
185-
{"algorithm as int", `{"algorithm":1,"key_protection_mechanism":"KEY_PROTECTION_VM","lifespan":"3600s"}`},
178+
{"lifespan as integer", `{"algorithm":1,"key_protection_mechanism":2,"lifespan":3600}`},
179+
{"lifespan missing s suffix", `{"algorithm":1,"key_protection_mechanism":2,"lifespan":"3600"}`},
180+
{"lifespan negative", `{"algorithm":1,"key_protection_mechanism":2,"lifespan":"-1s"}`},
186181
}
187182

188183
for _, tc := range badBodies {

0 commit comments

Comments
 (0)