Commit 2f6b8edc authored by Jacob Vosmaer's avatar Jacob Vosmaer

Use base64 and 32 bytes for secret

parent 77026839
package api
import (
"encoding/base64"
"fmt"
"io/ioutil"
"sync"
)
const numSecretBytes = 64
const numSecretBytes = 32
type Secret struct {
File string
......@@ -29,17 +30,24 @@ func (s *Secret) getBytes() []byte {
}
func (s *Secret) setBytes() ([]byte, error) {
bytes, err := ioutil.ReadFile(s.File)
base64Bytes, err := ioutil.ReadFile(s.File)
if err != nil {
return nil, fmt.Errorf("read Secret.File: %v", err)
}
if n := len(bytes); n != numSecretBytes {
return nil, fmt.Errorf("expected %d bytes in %s, found %d", bytes, s.File, n)
secretBytes := make([]byte, base64.StdEncoding.DecodedLen(len(base64Bytes)))
n, err := base64.StdEncoding.Decode(secretBytes, base64Bytes)
if err != nil {
return nil, fmt.Errorf("decode secret: %v", err)
}
if n != numSecretBytes {
return nil, fmt.Errorf("expected %d secretBytes in %s, found %d", numSecretBytes, s.File, n)
}
s.Lock()
defer s.Unlock()
s.bytes = bytes
s.bytes = secretBytes
return bytes, nil
return secretBytes, nil
}
AՃ+vy'jo8Bp"j6Slt܄&j˜׺;4/
\ No newline at end of file
+M8OJgJxoxdDRgOR0UT8sDbAgp/63y/XUNE3d8+tawA=
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment