@@ -31,61 +31,62 @@ func TestGenerateKeyPair(t *testing.T) {
31
31
32
32
for _ , tt := range tests {
33
33
t .Run (tt .name , func (t * testing.T ) {
34
- keyPair , err := GenerateKeyPair (tt .algorithm )
34
+ privateJWK , err := GeneratePrivateKey (tt .algorithm )
35
35
if (err != nil ) != tt .wantErr {
36
36
t .Errorf ("GenerateKeyPair(%s) error = %v, wantErr %v" , tt .algorithm , err , tt .wantErr )
37
37
return
38
38
}
39
39
if ! tt .wantErr {
40
- if keyPair == nil {
40
+ if privateJWK == nil {
41
41
t .Error ("GenerateKeyPair() returned nil key pair" )
42
42
return
43
43
}
44
44
45
45
// Check that both public and private keys are generated
46
- if keyPair .PublicKey .KeyType == "" {
46
+ publicJWK := privateJWK .ToPublicJWK ()
47
+ if publicJWK .KeyType == "" {
47
48
t .Error ("Public key type is empty" )
48
49
}
49
- if keyPair . PrivateKey .KeyType == "" {
50
+ if privateJWK .KeyType == "" {
50
51
t .Error ("Private key type is empty" )
51
52
}
52
53
53
54
// Check that key IDs match
54
- if keyPair . PublicKey . KeyID != keyPair . PrivateKey .KeyID {
55
+ if publicJWK . KeyID != privateJWK .KeyID {
55
56
t .Error ("Public and private key IDs don't match" )
56
57
}
57
58
58
59
// Algorithm-specific checks
59
60
switch tt .algorithm {
60
61
case config .AlgRS256 :
61
- if keyPair . PublicKey .KeyType != "RSA" {
62
- t .Errorf ("Expected RSA key type, got %s" , keyPair . PublicKey .KeyType )
62
+ if publicJWK .KeyType != "RSA" {
63
+ t .Errorf ("Expected RSA key type, got %s" , publicJWK .KeyType )
63
64
}
64
- if keyPair . PrivateKey .Algorithm != "RS256" {
65
- t .Errorf ("Expected RS256 algorithm, got %s" , keyPair . PrivateKey .Algorithm )
65
+ if privateJWK .Algorithm != "RS256" {
66
+ t .Errorf ("Expected RS256 algorithm, got %s" , privateJWK .Algorithm )
66
67
}
67
68
// Check that RSA-specific fields are present
68
- if keyPair . PrivateKey .Modulus == "" {
69
+ if privateJWK .Modulus == "" {
69
70
t .Error ("RSA private key missing modulus" )
70
71
}
71
- if keyPair . PrivateKey .PrivateExponent == "" {
72
+ if privateJWK .PrivateExponent == "" {
72
73
t .Error ("RSA private key missing private exponent" )
73
74
}
74
75
case config .AlgES256 :
75
- if keyPair . PublicKey .KeyType != "EC" {
76
- t .Errorf ("Expected EC key type, got %s" , keyPair . PublicKey .KeyType )
76
+ if publicJWK .KeyType != "EC" {
77
+ t .Errorf ("Expected EC key type, got %s" , publicJWK .KeyType )
77
78
}
78
- if keyPair . PrivateKey .Algorithm != "ES256" {
79
- t .Errorf ("Expected ES256 algorithm, got %s" , keyPair . PrivateKey .Algorithm )
79
+ if privateJWK .Algorithm != "ES256" {
80
+ t .Errorf ("Expected ES256 algorithm, got %s" , privateJWK .Algorithm )
80
81
}
81
82
// Check that EC-specific fields are present
82
- if keyPair . PrivateKey .Curve != "P-256" {
83
- t .Errorf ("Expected P-256 curve, got %s" , keyPair . PrivateKey .Curve )
83
+ if privateJWK .Curve != "P-256" {
84
+ t .Errorf ("Expected P-256 curve, got %s" , privateJWK .Curve )
84
85
}
85
- if keyPair . PrivateKey .X == "" {
86
+ if privateJWK .X == "" {
86
87
t .Error ("EC private key missing X coordinate" )
87
88
}
88
- if keyPair . PrivateKey .Y == "" {
89
+ if privateJWK .Y == "" {
89
90
t .Error ("EC private key missing Y coordinate" )
90
91
}
91
92
}
0 commit comments