MCPcopy Index your code
hub / github.com/cloudflare/cloudflared / fetchKey

Method fetchKey

token/encrypt.go:149–165  ·  view source on GitHub ↗

fetchKey will load a a DER formatted key from disk

(filename string)

Source from the content-addressed store, hash-verified

147
148// fetchKey will load a a DER formatted key from disk
149func (e *Encrypter) fetchKey(filename string) (*[32]byte, error) {
150 f, err := os.Open(filename)
151 if err != nil {
152 return nil, err
153 }
154 buf := new(bytes.Buffer)
155 io.Copy(buf, f)
156
157 p, _ := pem.Decode(buf.Bytes())
158 if p == nil {
159 return nil, errors.New("Failed to decode key")
160 }
161 var newKey [32]byte
162 copy(newKey[:], p.Bytes)
163
164 return &newKey, nil
165}
166
167// decodePublicKey will base64 decode the provided key to the box representation
168func (e *Encrypter) decodePublicKey(key string) (*[32]byte, error) {

Callers 1

fetchOrGenerateKeysMethod · 0.95

Calls 2

BytesMethod · 0.80
DecodeMethod · 0.45

Tested by

no test coverage detected