本文整理匯總了Golang中github.com/msecret/emp/objects.Hash.FromBytes方法的典型用法代碼示例。如果您正苦於以下問題:Golang Hash.FromBytes方法的具體用法?Golang Hash.FromBytes怎麽用?Golang Hash.FromBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/msecret/emp/objects.Hash
的用法示例。
在下文中一共展示了Hash.FromBytes方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: 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
}
示例2: 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
}
示例3: 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
}
示例4: OpenMessage
func (service *EMPService) OpenMessage(r *http.Request, args *[]byte, reply *objects.FullMessage) 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
}
if msg.Encrypted == nil {
*reply = *msg
return nil
}
// If not decrypted, decrypt message and purge
if msg.Decrypted == nil {
recipient, err := localdb.GetAddressDetail(objects.MakeHash(encryption.StringToAddress(msg.MetaMessage.Recipient)))
if err != nil {
return err
}
if recipient.Privkey == nil {
*reply = *msg
return nil
}
// Decrypt Message
decrypted := encryption.Decrypt(service.Config.Log, recipient.Privkey, msg.Encrypted)
if len(decrypted) == 0 {
*reply = *msg
return nil
}
msg.Decrypted = new(objects.DecryptedMessage)
msg.Decrypted.FromBytes(decrypted)
// Update Sender
x, y := encryption.UnmarshalPubkey(msg.Decrypted.Pubkey[:])
address := encryption.GetAddress(service.Config.Log, x, y)
addrStr := encryption.AddressToString(address)
addrHash := objects.MakeHash(address)
detail, _ := localdb.GetAddressDetail(addrHash)
if detail == nil {
detail = new(objects.AddressDetail)
}
detail.Address = address
detail.String = addrStr
detail.Pubkey = msg.Decrypted.Pubkey[:]
localdb.AddUpdateAddress(detail)
msg.MetaMessage.Sender = detail.String
// Send Purge Request
purge := new(objects.Purge)
purge.Txid = msg.Decrypted.Txid
service.Config.RecvQueue <- *objects.MakeFrame(objects.PURGE, objects.BROADCAST, purge)
msg.MetaMessage.Purged = true
localdb.AddUpdateMessage(msg, localdb.Contains(msg.MetaMessage.TxidHash))
} else {
if msg.MetaMessage.Purged == false && localdb.Contains(txidHash) == localdb.INBOX {
msg.MetaMessage.Purged = true
localdb.AddUpdateMessage(msg, localdb.Contains(msg.MetaMessage.TxidHash))
}
}
*reply = *msg
return nil
}
示例5: DeleteMessage
func (service *EMPService) DeleteMessage(r *http.Request, args *[]byte, reply *NilParam) error {
txidHash := new(objects.Hash)
txidHash.FromBytes(*args)
return localdb.DeleteMessage(txidHash)
}
示例6: Start
// Starts a new TCP Server wth configuration specified in ApiConfig.
// Server will terminate cleanly only when data is sent to the Quit channel.
//
// See (struct ApiConfig) for details.
func Start(config *ApiConfig) {
var err error
var frame quibit.Frame
defer quit(config)
config.Log <- "Starting api..."
// Start Database Services
err = db.Initialize(config.Log, config.DbFile)
defer db.Cleanup()
if err != nil {
config.Log <- fmt.Sprintf("Error initializing database: %s", err)
config.Log <- "Quit"
return
}
config.LocalVersion.Timestamp = time.Now().Round(time.Second)
locVersion := objects.MakeFrame(objects.VERSION, objects.REQUEST, &config.LocalVersion)
for str, _ := range config.NodeList.Nodes {
locVersion.Peer = str
config.SendQueue <- *locVersion
}
// Set Up Clocks
second := time.Tick(2 * time.Second)
minute := time.Tick(time.Minute)
for {
select {
case frame = <-config.RecvQueue:
config.Log <- fmt.Sprintf("Received %s frame...", CmdString(frame.Header.Command))
switch frame.Header.Command {
case objects.VERSION:
version := new(objects.Version)
err = version.FromBytes(frame.Payload)
if err != nil {
config.Log <- fmt.Sprintf("Error parsing version: %s", err)
} else {
fVERSION(config, frame, version)
}
case objects.PEER:
nodeList := new(objects.NodeList)
err = nodeList.FromBytes(frame.Payload)
if err != nil {
config.Log <- fmt.Sprintf("Error parsing peer list: %s", err)
} else {
fPEER(config, frame, nodeList)
}
case objects.OBJ:
obj := new(objects.Obj)
err = obj.FromBytes(frame.Payload)
if err != nil {
config.Log <- fmt.Sprintf("Error parsing obj list: %s", err)
} else {
fOBJ(config, frame, obj)
}
case objects.GETOBJ:
getObj := new(objects.Hash)
if len(frame.Payload) == 0 {
break
}
err = getObj.FromBytes(frame.Payload)
if err != nil {
config.Log <- fmt.Sprintf("Error parsing getobj hash: %s", err)
} else {
fGETOBJ(config, frame, getObj)
}
case objects.PUBKEY_REQUEST:
pubReq := new(objects.Hash)
err = pubReq.FromBytes(frame.Payload)
if err != nil {
config.Log <- fmt.Sprintf("Error parsing pubkey request hash: %s", err)
} else {
fPUBKEY_REQUEST(config, frame, pubReq)
}
case objects.PUBKEY:
pub := new(objects.EncryptedPubkey)
err = pub.FromBytes(frame.Payload)
if err != nil {
config.Log <- fmt.Sprintf("Error parsing pubkey: %s", err)
} else {
fPUBKEY(config, frame, pub)
}
case objects.MSG:
msg := new(objects.Message)
err = msg.FromBytes(frame.Payload)
if err != nil {
config.Log <- fmt.Sprintf("Error parsing message: %s", err)
} else {
fMSG(config, frame, msg)
}
case objects.PUB:
msg := new(objects.Message)
err = msg.FromBytes(frame.Payload)
if err != nil {
//.........這裏部分代碼省略.........