本文整理匯總了Golang中github.com/msecret/emp/objects.Hash類的典型用法代碼示例。如果您正苦於以下問題:Golang Hash類的具體用法?Golang Hash怎麽用?Golang Hash使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Hash類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetPubkey
// Get Encrypted Public Key from database.
func GetPubkey(log chan string, addrHash objects.Hash) *objects.EncryptedPubkey {
mutex.Lock()
defer mutex.Unlock()
hash := addrHash.GetBytes()
if hashList == nil || dbConn == nil {
return nil
}
if hashList[string(hash)] != PUBKEY {
return nil
}
for s, err := dbConn.Query("SELECT payload FROM pubkey WHERE hash=?", hash); err == nil; err = s.Next() {
var payload []byte
s.Scan(&payload) // Assigns 1st column to rowid, the rest to row
pub := new(objects.EncryptedPubkey)
pub.AddrHash = addrHash
copy(pub.IV[:], payload[:16])
pub.Payload = payload[16:]
return pub
}
// Not Found
return nil
}
示例2: AddPurge
// Add Purge Token to database, and remove corresponding message if necessary.
func AddPurge(log chan string, p objects.Purge) error {
mutex.Lock()
defer mutex.Unlock()
txid := p.GetBytes()
hashArr := sha512.Sum384(txid)
hash := hashArr[:]
if hashList == nil || dbConn == nil {
return DBError(EUNINIT)
}
hashObj := new(objects.Hash)
hashObj.FromBytes(hash)
if Contains(*hashObj) == PURGE {
return nil
}
err := dbConn.Exec("INSERT INTO purge VALUES (?, ?)", hash, txid)
if err != nil {
log <- fmt.Sprintf("Error inserting purge into db... %s", err)
return err
}
Add(*hashObj, PURGE)
return nil
}
示例3: GetMessage
// Get basic message from database.
func GetMessage(log chan string, txidHash objects.Hash) *objects.Message {
mutex.Lock()
defer mutex.Unlock()
hash := txidHash.GetBytes()
if hashList == nil || dbConn == nil {
return nil
}
if hashList[string(hash)] != MSG && hashList[string(hash)] != PUB {
return nil
}
msg := new(objects.Message)
for s, err := dbConn.Query("SELECT * FROM msg WHERE hash=?", hash); err == nil; err = s.Next() {
var timestamp int64
encrypted := make([]byte, 0, 0)
txidhash := make([]byte, 0, 0)
addrhash := make([]byte, 0, 0)
s.Scan(&txidhash, &addrhash, ×tamp, &encrypted)
msg.TxidHash.FromBytes(txidhash)
msg.AddrHash.FromBytes(addrhash)
msg.Timestamp = time.Unix(timestamp, 0)
msg.Content.FromBytes(encrypted)
return msg
}
// Not Found
return nil
}
示例4: RemoveHash
// Remove any object from the database and hash list.
func RemoveHash(log chan string, hashObj objects.Hash) error {
mutex.Lock()
defer mutex.Unlock()
hash := hashObj.GetBytes()
if hashList == nil || dbConn == nil {
return DBError(EUNINIT)
}
var sql string
switch Contains(hashObj) {
case PUBKEY:
sql = "DELETE FROM pubkey WHERE hash=?"
case MSG:
sql = "DELETE FROM msg WHERE hash=?"
case PURGE:
sql = "DELETE FROM purge WHERE hash=?"
default:
return nil
}
err := dbConn.Exec(sql, hash)
if err != nil {
log <- fmt.Sprintf("Error deleting hash from db... %s", err)
return nil
}
Delete(hashObj)
return nil
}
示例5: DeleteAddress
func DeleteAddress(addrHash *objects.Hash) error {
localMutex.Lock()
defer localMutex.Unlock()
if Contains(*addrHash) > ADDRESS {
return errors.New("Error Deleting Message: Not Found!")
}
return LocalDB.Exec("DELETE FROM addressbook WHERE hash=?", addrHash.GetBytes())
}
示例6: DeleteMessage
func DeleteMessage(txidHash *objects.Hash) error {
localMutex.Lock()
defer localMutex.Unlock()
if Contains(*txidHash) > SENDBOX {
return errors.New("Error Deleting Message: Not Found!")
}
return LocalDB.Exec("DELETE FROM msg WHERE txid_hash=?", txidHash.GetBytes())
}
示例7: Contains
// Get type of object in Hash List
func Contains(hashObj objects.Hash) int {
hash := string(hashObj.GetBytes())
if hashList != nil {
hashType, ok := hashList[hash]
if ok {
return hashType
} else {
return NOTFOUND
}
}
return NOTFOUND
}
示例8: ObjList
// List of all hashes in the hash list.
func ObjList() *objects.Obj {
if hashList == nil {
return nil
}
ret := new(objects.Obj)
ret.HashList = make([]objects.Hash, 0, 0)
hash := new(objects.Hash)
for key, _ := range hashList {
hash.FromBytes([]byte(key))
ret.HashList = append(ret.HashList, *hash)
}
return ret
}
示例9: GetEncrypted
func (service *EMPService) GetEncrypted(r *http.Request, args *[]byte, reply *encryption.EncryptedMessage) error {
if !basicAuth(service.Config, r) {
service.Config.Log <- fmt.Sprintf("Unauthorized RPC Request from: %s", r.RemoteAddr)
return errors.New("Unauthorized")
}
var txidHash objects.Hash
txidHash.FromBytes(*args)
// Get Message from Database
msg, err := localdb.GetMessageDetail(txidHash)
if err != nil {
return err
}
*reply = *msg.Encrypted
return nil
}
示例10: GetMessageDetail
func GetMessageDetail(txidHash objects.Hash) (*objects.FullMessage, error) {
localMutex.Lock()
defer localMutex.Unlock()
if Contains(txidHash) > SENDBOX {
return nil, errors.New("Message not found!")
}
ret := new(objects.FullMessage)
ret.Encrypted = new(encryption.EncryptedMessage)
ret.Decrypted = new(objects.DecryptedMessage)
s, err := LocalDB.Query("SELECT * FROM msg WHERE txid_hash=?", txidHash.GetBytes())
if err == nil {
recipient := make([]byte, 0, 0)
sender := make([]byte, 0, 0)
encrypted := make([]byte, 0, 0)
decrypted := make([]byte, 0, 0)
txidHash := make([]byte, 0, 0)
var timestamp int64
var purged bool
var box int
s.Scan(&txidHash, &recipient, ×tamp, &box, &encrypted, &decrypted, &purged, &sender)
ret.MetaMessage.TxidHash.FromBytes(txidHash)
ret.MetaMessage.Recipient = encryption.AddressToString(recipient)
ret.MetaMessage.Sender = encryption.AddressToString(sender)
ret.MetaMessage.Timestamp = time.Unix(timestamp, 0)
ret.MetaMessage.Purged = purged
ret.Encrypted.FromBytes(encrypted)
if len(decrypted) > 0 {
ret.Decrypted.FromBytes(decrypted)
} else {
ret.Decrypted = nil
}
return ret, nil
}
return nil, err
}
示例11: DeleteObject
func DeleteObject(obj objects.Hash) error {
var err error
switch Contains(obj) {
case INBOX:
fallthrough
case SENDBOX:
fallthrough
case OUTBOX:
err = LocalDB.Exec("DELETE FROM msg WHERE txid_hash=?", obj.GetBytes())
case ADDRESS:
err = LocalDB.Exec("DELETE FROM addressbook WHERE hash=?", obj.GetBytes())
default:
err = errors.New("Hash not found!")
}
if err == nil {
Del(obj)
}
return err
}
示例12: GetPurge
// Get purge token from the database.
func GetPurge(log chan string, txidHash objects.Hash) *objects.Purge {
mutex.Lock()
defer mutex.Unlock()
hash := txidHash.GetBytes()
if hashList == nil || dbConn == nil {
return nil
}
if hashList[string(hash)] != PURGE {
return nil
}
for s, err := dbConn.Query("SELECT txid FROM purge WHERE hash=?", hash); err == nil; err = s.Next() {
var txid []byte
s.Scan(&txid) // Assigns 1st column to rowid, the rest to row
p := new(objects.Purge)
p.FromBytes(txid)
return p
}
// Not Found
return nil
}
示例13: DeleteMessage
func (service *EMPService) DeleteMessage(r *http.Request, args *[]byte, reply *NilParam) error {
txidHash := new(objects.Hash)
txidHash.FromBytes(*args)
return localdb.DeleteMessage(txidHash)
}
示例14: Del
// Delete hash from Hash List
func Del(hashObj objects.Hash) {
hash := string(hashObj.GetBytes())
if hashList != nil {
delete(hashList, hash)
}
}
示例15: Add
// Add to global Hash List.
func Add(hashObj objects.Hash, hashType int) {
hash := string(hashObj.GetBytes())
if hashList != nil {
hashList[hash] = hashType
}
}