-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreds.go
More file actions
39 lines (32 loc) · 779 Bytes
/
creds.go
File metadata and controls
39 lines (32 loc) · 779 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 transip
import (
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"errors"
"io/ioutil"
)
type Client struct {
Login string // Login to TransIP website
PrivateKey *rsa.PrivateKey // Private key for API
ReadWrite bool // Read+Write mode?
}
func (c *Client) SetPrivateKeyFromPath(path string) error {
contents, err := ioutil.ReadFile(path)
if err != nil {
return err
}
return c.SetPrivateKeyFromBytes(contents)
}
func (c *Client) SetPrivateKeyFromBytes(keyContents []byte) error {
block, _ := pem.Decode(keyContents)
if block == nil {
return errors.New("could not decode pem file")
}
privKey, err := x509.ParsePKCS8PrivateKey(block.Bytes)
if err != nil {
return err
}
c.PrivateKey = privKey.(*rsa.PrivateKey)
return nil
}