MCPcopy Create free account
hub / github.com/PasarGuard/node / GetPreSharedKey

Method GetPreSharedKey

backend/wireguard/config.go:138–166  ·  view source on GitHub ↗

GetPreSharedKey parses and caches the pre-shared key, optionally returning nil if not set.

()

Source from the content-addressed store, hash-verified

136
137// GetPreSharedKey parses and caches the pre-shared key, optionally returning nil if not set.
138func (c *Config) GetPreSharedKey() (*wgtypes.Key, error) {
139 c.mu.RLock()
140 if c.presharedKeySet {
141 c.mu.RUnlock()
142 return c.presharedKeyValue, nil
143 }
144 c.mu.RUnlock()
145
146 c.mu.Lock()
147 defer c.mu.Unlock()
148
149 if c.presharedKeySet {
150 return c.presharedKeyValue, nil
151 }
152
153 if c.PreSharedKey == "" {
154 c.presharedKeySet = true
155 c.presharedKeyValue = nil
156 return nil, nil
157 }
158
159 key, err := wgtypes.ParseKey(c.PreSharedKey)
160 if err != nil {
161 return nil, err
162 }
163 c.presharedKeyValue = &key
164 c.presharedKeySet = true
165 return &key, nil
166}
167
168// GenerateKeyPair generates a new WireGuard key pair
169func GenerateKeyPair() (privateKey, publicKey string, err error) {

Callers 4

buildSyncDiffMethod · 0.80
newWithManagerFactoryFunction · 0.80
restartLockedMethod · 0.80
syncUsersFullMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected