forked from gokalkan/gokalkan
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_key_store.go
More file actions
39 lines (30 loc) · 958 Bytes
/
load_key_store.go
File metadata and controls
39 lines (30 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package gokalkan
import (
"bytes"
"fmt"
"io"
"os"
"github.com/gokalkan/gokalkan/ckalkan"
)
// LoadKeyStore загружает PKCS12.
func (cli *Client) LoadKeyStore(path, password string) error {
return cli.kc.LoadKeyStore(password, path, ckalkan.StoreTypePKCS12, "")
}
// LoadKeyStoreFromBytes загружает PKCS12.
func (cli *Client) LoadKeyStoreFromBytes(key []byte, password string) (err error) {
tmpKey, err := os.CreateTemp("", "tmp.key.*.p12")
if err != nil {
return fmt.Errorf("%w: %s", ErrLoadKey, err)
}
filename := tmpKey.Name()
defer os.Remove(filename)
defer tmpKey.Close()
written, err := io.Copy(tmpKey, bytes.NewReader(key))
if err != nil {
return fmt.Errorf("%w: %s", ErrLoadKey, err)
}
if exp := int64(len(key)); exp != written {
return fmt.Errorf("%w: expected %d bytes, but written %d bytes", ErrLoadKey, exp, written)
}
return cli.kc.LoadKeyStore(password, filename, ckalkan.StoreTypePKCS12, "")
}