MCPcopy Create free account
hub / github.com/Driver-C/tryssh / GetCachedMasterKey

Function GetCachedMasterKey

pkg/utils/crypto.go:74–92  ·  view source on GitHub ↗

GetCachedMasterKey returns the master key only if already cached or available via the environment variable, without prompting interactively.

()

Source from the content-addressed store, hash-verified

72// GetCachedMasterKey returns the master key only if already cached or available
73// via the environment variable, without prompting interactively.
74func GetCachedMasterKey() ([]byte, error) {
75 masterKeyMu.Lock()
76 defer masterKeyMu.Unlock()
77
78 if len(masterKey) > 0 {
79 return masterKey, nil
80 }
81
82 if envKey := os.Getenv(keyEnvVar); envKey != "" {
83 key, err := deriveKey([]byte(envKey))
84 if err != nil {
85 return nil, err
86 }
87 masterKey = key
88 return masterKey, nil
89 }
90
91 return nil, nil
92}
93
94// ClearMasterKey removes the cached master key from memory.
95func ClearMasterKey() {

Callers 4

encryptConfigForSaveFunction · 0.92

Calls 1

deriveKeyFunction · 0.85