本文整理匯總了Golang中github.com/msecret/emp/objects.Hash.GetBytes方法的典型用法代碼示例。如果您正苦於以下問題:Golang Hash.GetBytes方法的具體用法?Golang Hash.GetBytes怎麽用?Golang Hash.GetBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/msecret/emp/objects.Hash
的用法示例。
在下文中一共展示了Hash.GetBytes方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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
}
示例3: 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
}
示例4: 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())
}
示例5: 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())
}
示例6: 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
}
示例7: 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
}
示例8: 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
}
示例9: 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
}
示例10: Del
// Delete hash from Hash List
func Del(hashObj objects.Hash) {
hash := string(hashObj.GetBytes())
if hashList != nil {
delete(hashList, hash)
}
}
示例11: Add
// Add to global Hash List.
func Add(hashObj objects.Hash, hashType int) {
hash := string(hashObj.GetBytes())
if hashList != nil {
hashList[hash] = hashType
}
}
示例12: GetAddressDetail
func GetAddressDetail(addrHash objects.Hash) (*objects.AddressDetail, error) {
localMutex.Lock()
defer localMutex.Unlock()
if Contains(addrHash) != ADDRESS {
return nil, errors.New("Address not found!")
}
ret := new(objects.AddressDetail)
s, err := LocalDB.Query("SELECT address, registered, pubkey, privkey, label, subscribed, encprivkey FROM addressbook WHERE hash=?", addrHash.GetBytes())
if err == nil {
s.Scan(&ret.Address, &ret.IsRegistered, &ret.Pubkey, &ret.Privkey, &ret.Label, &ret.IsSubscribed, &ret.EncPrivkey)
ret.String = encryption.AddressToString(ret.Address)
return ret, nil
}
return nil, err
}