GetPreSharedKey parses and caches the pre-shared key, optionally returning nil if not set.
()
| 136 | |
| 137 | // GetPreSharedKey parses and caches the pre-shared key, optionally returning nil if not set. |
| 138 | func (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 |
| 169 | func GenerateKeyPair() (privateKey, publicKey string, err error) { |
no outgoing calls
no test coverage detected