-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.go
47 lines (38 loc) · 1.19 KB
/
config.go
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
40
41
42
43
44
45
46
47
package identity
import (
"encoding/base64"
"fmt"
"github.com/TankerHQ/identity-go/v3/internal/app"
)
// Config wraps information about an app
type Config struct {
// AppID is the ID of the app corresponding to this config
AppID string
// AppSecret is a secret used to create identities
AppSecret string
}
type config struct {
AppID []byte
AppSecret []byte
}
func (cfg Config) fromBase64() (*config, error) {
var (
newCfg = new(config)
err error
)
newCfg.AppID, err = base64.StdEncoding.DecodeString(cfg.AppID)
if err != nil {
return nil, fmt.Errorf("unable to decode AppID '%s', should be a valid base64 string", cfg.AppID)
}
if len(newCfg.AppID) != app.AppPublicKeySize {
return nil, fmt.Errorf("wrong byte size for AppID: %d, should be %d", len(newCfg.AppID), app.AppPublicKeySize)
}
newCfg.AppSecret, err = base64.StdEncoding.DecodeString(cfg.AppSecret)
if err != nil {
return nil, fmt.Errorf("unable to decode AppSecret '%s', should be a valid base64 string", cfg.AppSecret)
}
if len(newCfg.AppSecret) != app.AppSecretSize {
return nil, fmt.Errorf("wrong byte size for AppSecret: %d, should be %d", len(newCfg.AppSecret), app.AppSecretSize)
}
return newCfg, nil
}