Example #1
0
func (db *T) GetMainKey() (*ecdsa.PrivateKey, error) {
	dbtx, err := db.DB.Begin(false)
	defer dbtx.Rollback()
	if err != nil {
		return nil, err
	}
	bucket := dbtx.Bucket([]byte("keys"))
	if bucket == nil {
		return nil, nil // return no error because there were no keys saved
	}
	main := bucket.Get([]byte("main"))
	var key []byte
	if main == nil {
		keys := db.ListKeys()
		if len(keys) == 0 {
			return nil, nil
		} else {
			key = bucket.Get([]byte(keys[0]))
		}
	} else {
		key = bucket.Get(main)
	}
	if key == nil {
		return nil, nil
	} else {
		decodedKey, err := keys.DecodeECDSAPrivateKey(key)
		if err != nil {
			return nil, err
		}
		return decodedKey, nil
	}
}
Example #2
0
func (db *T) GetMainKey() (k *ecdsa.PrivateKey, e error) {
	readable(&e, db, func(dbtx *bolt.Tx) {
		bucket := dbtx.Bucket([]byte("keys"))
		if bucket == nil {
			return // return no error because there were no keys saved
		}
		main := bucket.Get([]byte("main"))
		var key []byte
		if main == nil {
			keys := db.ListKeys()
			if len(keys) == 0 {
				return
			} else {
				key = bucket.Get([]byte(keys[0]))
			}
		} else {
			key = bucket.Get(main)
		}
		if key == nil {
			return
		} else {
			k, e = keys.DecodeECDSAPrivateKey(key)
		}
	})
	return
}
Example #3
0
func (db *T) GetKey(alias string) (k *ecdsa.PrivateKey, e error) {
	readable(&e, db, func(dbtx *bolt.Tx) {
		bucket := dbtx.Bucket([]byte("keys"))
		if bucket == nil {
			return // return no error because there were no keys saved
		}
		key := bucket.Get([]byte(alias))
		if key == nil {
			return
		} else {
			k, e = keys.DecodeECDSAPrivateKey(key)
		}
	})
	return
}
Example #4
0
func (db *T) GetKey(alias string) (*ecdsa.PrivateKey, error) {
	dbtx, err := db.DB.Begin(false)
	defer dbtx.Rollback()
	if err != nil {
		return nil, err
	}
	bucket := dbtx.Bucket([]byte("keys"))
	if bucket == nil {
		return nil, nil // return no error because there were no keys saved
	}
	key := bucket.Get([]byte(alias))
	if key == nil {
		return nil, nil
	} else {
		decodedKey, err := keys.DecodeECDSAPrivateKey(key)
		if err != nil {
			return nil, err
		}
		return decodedKey, nil
	}
}