LoadOrGenNodeKey attempts to load the NodeKey from the given filePath. If the file does not exist, it generates and saves a new NodeKey.
(filePath string)
| 48 | // LoadOrGenNodeKey attempts to load the NodeKey from the given filePath. If |
| 49 | // the file does not exist, it generates and saves a new NodeKey. |
| 50 | func LoadOrGenNodeKey(filePath string) (*NodeKey, error) { |
| 51 | if tmos.FileExists(filePath) { |
| 52 | nodeKey, err := LoadNodeKey(filePath) |
| 53 | if err != nil { |
| 54 | return nil, err |
| 55 | } |
| 56 | return nodeKey, nil |
| 57 | } |
| 58 | |
| 59 | privKey := ed25519.GenPrivKey() |
| 60 | nodeKey := &NodeKey{ |
| 61 | PrivKey: privKey, |
| 62 | } |
| 63 | |
| 64 | if err := nodeKey.SaveAs(filePath); err != nil { |
| 65 | return nil, err |
| 66 | } |
| 67 | |
| 68 | return nodeKey, nil |
| 69 | } |
| 70 | |
| 71 | // LoadNodeKey loads NodeKey located in filePath. |
| 72 | func LoadNodeKey(filePath string) (*NodeKey, error) { |