mirror of
https://github.com/1f349/mjwt.git
synced 2024-12-22 07:24:05 +00:00
Fix up KeyStore directory read.
This commit is contained in:
parent
a0d03c0dfb
commit
a94ed7a2e5
19
key_store.go
19
key_store.go
@ -42,12 +42,14 @@ func NewMJwtKeyStoreFromDirectory(directory, keyPrvExt, keyPubExt string) (KeySt
|
||||
}
|
||||
// Import keys from files, based on extension
|
||||
for _, entry := range dirEntries {
|
||||
if !entry.IsDir() {
|
||||
firstDotIdx := strings.Index(entry.Name(), ".")
|
||||
lastDotIdx := strings.LastIndex(entry.Name(), ".")
|
||||
if firstDotIdx > 0 && lastDotIdx+1 < len(entry.Name()) {
|
||||
if entry.Name()[lastDotIdx+1:] == keyPrvExt {
|
||||
kID := entry.Name()[:firstDotIdx]
|
||||
if entry.IsDir() {
|
||||
continue
|
||||
}
|
||||
kID, _, _ := strings.Cut(entry.Name(), ".")
|
||||
if kID == "" {
|
||||
continue
|
||||
}
|
||||
if path.Ext(entry.Name()) == "."+keyPrvExt {
|
||||
// Load rsa private key with the file name as the kID (Up to the first .)
|
||||
key, err2 := rsaprivate.Read(path.Join(directory, entry.Name()))
|
||||
if err2 == nil {
|
||||
@ -56,8 +58,7 @@ func NewMJwtKeyStoreFromDirectory(directory, keyPrvExt, keyPubExt string) (KeySt
|
||||
} else {
|
||||
err = err2
|
||||
}
|
||||
} else if entry.Name()[lastDotIdx+1:] == keyPubExt {
|
||||
kID := entry.Name()[:firstDotIdx]
|
||||
} else if path.Ext(entry.Name()) == "."+keyPubExt {
|
||||
// Load rsa public key with the file name as the kID (Up to the first .)
|
||||
key, err2 := rsapublic.Read(path.Join(directory, entry.Name()))
|
||||
if err2 == nil {
|
||||
@ -71,8 +72,6 @@ func NewMJwtKeyStoreFromDirectory(directory, keyPrvExt, keyPubExt string) (KeySt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ks, err
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user