forked from mutecomm/mute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
procuid.go
32 lines (28 loc) · 934 Bytes
/
procuid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright (c) 2015 Mute Communications Ltd.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package msg
import (
"github.com/mutecomm/mute/cipher"
"github.com/mutecomm/mute/uid"
)
type procUIDResult struct {
uidIndex []byte // UIDIndex = SHA256(SHA256(UIDMessage))
msg *uid.Message // decoded UID message
err error
}
// procUID allows to process a sender UID from the header in parallel.
// senderUID is the JSON encoded UID message parsed from the header, res is
// the result channel used to communicate the result of the calculation.
func procUID(senderUID string, res chan *procUIDResult) {
var r procUIDResult
var err error
r.uidIndex = cipher.SHA256(cipher.SHA256([]byte(senderUID)))
r.msg, err = uid.NewJSON(senderUID)
if err != nil {
res <- &procUIDResult{uidIndex: nil, msg: nil, err: err}
return
}
// return results
res <- &r
}