MCPcopy
hub / github.com/dgraph-io/dgraph / readKey

Function readKey

dgraph/cmd/cert/create.go:96–112  ·  view source on GitHub ↗

readKey tries to read and decode the contents of a private key file. Returns the private key, or error otherwise.

(keyFile string)

Source from the content-addressed store, hash-verified

94// readKey tries to read and decode the contents of a private key file.
95// Returns the private key, or error otherwise.
96func readKey(keyFile string) (crypto.PrivateKey, error) {
97 b, err := os.ReadFile(keyFile)
98 if err != nil {
99 return nil, err
100 }
101
102 block, _ := pem.Decode(b)
103 switch {
104 case block == nil:
105 return nil, errors.Errorf("Failed to read key block")
106 case block.Type == "EC PRIVATE KEY":
107 return x509.ParseECPrivateKey(block.Bytes)
108 case block.Type == "RSA PRIVATE KEY":
109 return x509.ParsePKCS1PrivateKey(block.Bytes)
110 }
111 return nil, errors.Errorf("Unknown PEM type: %s", block.Type)
112}
113
114// readCert tries to read and decode the contents of a signed cert file.
115// Returns the x509v3 cert, or error otherwise.

Callers 4

getFileInfoFunction · 0.85
makeKeyFunction · 0.85
createNodePairFunction · 0.85
createClientPairFunction · 0.85

Calls 1

ErrorfMethod · 0.45

Tested by

no test coverage detected