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