-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop/v2' into flexible-raw-keys
- Loading branch information
Showing
18 changed files
with
107 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package examples | ||
|
||
import ( | ||
"crypto/rand" | ||
"crypto/rsa" | ||
"fmt" | ||
|
||
"github.com/lestrrat-go/jwx/v2/jwk" | ||
) | ||
|
||
func ExampleJWK_Comparison() { | ||
genKey := func() (jwk.Key, error) { | ||
raw, err := rsa.GenerateKey(rand.Reader, 2048) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to generate new RSA private key: %s", err) | ||
} | ||
|
||
key, err := jwk.FromRaw(raw) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create RSA key: %s", err) | ||
} | ||
if _, ok := key.(jwk.RSAPrivateKey); !ok { | ||
return nil, fmt.Errorf("expected jwk.SymmetricKey, got %T", key) | ||
} | ||
|
||
return key, nil | ||
} | ||
|
||
k1, err := genKey() | ||
if err != nil { | ||
fmt.Printf("failed to generate key 1: %T", err) | ||
return | ||
} | ||
k2, err := genKey() | ||
if err != nil { | ||
fmt.Printf("failed to generate key 2: %T", err) | ||
return | ||
} | ||
|
||
// This comparison only compares Thumbprints of each key. It does NOT take into | ||
// account fields that could differ even when thumbprints match. For example, | ||
// it is totally possible to have a key with the same thumbprint, but different | ||
// Key IDs, or key usages. | ||
if jwk.Equal(k1, k2) { | ||
fmt.Printf("k1 and k2 should be different") | ||
return | ||
} | ||
|
||
if !jwk.Equal(k1, k1) { | ||
fmt.Printf("k1 and k1 should be equal") | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.