MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / InitPublicKeyStore

Function InitPublicKeyStore

crypto/kms/pubkeystore.go:129–176  ·  view source on GitHub ↗

InitPublicKeyStore opens a db file, if not exist, creates it. and creates a bucket if not exist.

(dbPath string, initNodes []proto.Node)

Source from the content-addressed store, hash-verified

127// InitPublicKeyStore opens a db file, if not exist, creates it.
128// and creates a bucket if not exist.
129func InitPublicKeyStore(dbPath string, initNodes []proto.Node) (err error) {
130 //testFlag := flag.Lookup("test")
131 //log.Debugf("%#v %#v", testFlag, testFlag.Value)
132 // close already opened public key store
133 ClosePublicKeyStore()
134
135 pksLock.Lock()
136 InitBP()
137
138 var strg *xs.SQLite3
139
140 if strg, err = func() (strg *xs.SQLite3, err error) {
141 // test if the keystore is a valid sqlite database
142 // if so, truncate and upgrade to new version
143
144 if err = removeFileIfIsNotSQLite(dbPath); err != nil {
145 return
146 }
147 if strg, err = xs.NewSqlite(dbPath); err != nil {
148 return
149 }
150 if _, err = strg.Writer().Exec(initTableSQL); err != nil {
151 return
152 }
153
154 return
155 }(); err != nil {
156 pksLock.Unlock()
157 log.WithError(err).Error("InitPublicKeyStore failed")
158 return
159 }
160
161 // pks is the singleton instance
162 pks = &PublicKeyStore{
163 db: strg,
164 }
165 pksLock.Unlock()
166
167 for _, n := range initNodes {
168 err = setNode(&n)
169 if err != nil {
170 err = errors.Wrap(err, "set init nodes failed")
171 return
172 }
173 }
174
175 return
176}
177
178// GetPublicKey gets a PublicKey of given id
179// Returns an error if the id was not found.

Callers 8

setupFunction · 0.92
setupFunction · 0.92
InitMethod · 0.92
initNodePeersFunction · 0.92
InitKMSFunction · 0.92
TestDBFunction · 0.85
TestErrorPathFunction · 0.85

Calls 8

WriterMethod · 0.95
WithErrorFunction · 0.92
ClosePublicKeyStoreFunction · 0.85
InitBPFunction · 0.85
removeFileIfIsNotSQLiteFunction · 0.85
setNodeFunction · 0.85
ErrorMethod · 0.80
ExecMethod · 0.65

Tested by 5

setupFunction · 0.74
setupFunction · 0.74
TestDBFunction · 0.68
TestErrorPathFunction · 0.68