| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- package truststore
- import (
- "crypto"
- "fmt"
- "log/slog"
- "path/filepath"
- )
- // TrustStore is a generic interface to retrieve a public key
- type TrustStore interface {
- GetPublicKey(keyID string) crypto.PublicKey
- }
- // InMemoryTrustStore is a in memory storage for public keys
- type InMemoryTrustStore struct {
- Keys map[string]crypto.PublicKey
- }
- // GetPublicKey returns the public key with this key ID
- func (ts *InMemoryTrustStore) GetPublicKey(keyID string) crypto.PublicKey {
- if key, ok := ts.Keys[keyID]; ok {
- return key
- }
- return nil
- }
- // New creates new Trust Store from URI
- func New(filename string) (store TrustStore, err error) {
- if filename == "" {
- return nil, nil
- }
- slog.Debug("loading truststore...", "filname", filename)
- switch filepath.Ext(filename) {
- case ".pem":
- store, err = newPEMTrustStore(filename)
- case ".p12":
- store, err = newP12TrustStore(filename)
- default:
- err = fmt.Errorf("unsupported truststore file format: %s", filename)
- }
- return
- }
|