本文整理汇总了Golang中golang.org/x/crypto/otr.PrivateKey.Fingerprint方法的典型用法代码示例。如果您正苦于以下问题:Golang PrivateKey.Fingerprint方法的具体用法?Golang PrivateKey.Fingerprint怎么用?Golang PrivateKey.Fingerprint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类golang.org/x/crypto/otr.PrivateKey
的用法示例。
在下文中一共展示了PrivateKey.Fingerprint方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
flag.Parse()
log.SetFlags(log.Ldate | log.Lmicroseconds | log.Lshortfile)
prv := otr.PrivateKey{}
if *genKey {
prv.Generate(rand.Reader)
fmt.Println(base64.RawStdEncoding.EncodeToString(prv.Serialize(nil)))
return
}
if *prvDataEnc == "" {
log.Fatalln("You have to provide OTR key")
}
prvData, err := base64.RawStdEncoding.DecodeString(*prvDataEnc)
if err != nil {
log.Fatalln("Invalid private key's Base64 encoding:", err)
}
if _, ok := prv.Parse(prvData); !ok {
log.Fatalln("Unable to parse private key")
}
log.Println("Our fingerprint:", hex.EncodeToString(prv.Fingerprint()))
var wg sync.WaitGroup
var ctin *os.File
var ctout *os.File
var ptin *os.File
var ptout *os.File
opener := func(fdd **os.File, path string, flag int) {
fd, err := os.OpenFile(path, flag, os.FileMode(0600))
if err != nil {
log.Fatalln("Unable to open", path, "file:", err)
}
*fdd = fd
wg.Done()
}
wg.Add(1)
go opener(&ctin, *ctInPath, os.O_RDONLY)
wg.Add(1)
go opener(&ptin, *ptInPath, os.O_RDONLY)
wg.Add(1)
go opener(&ctout, *ctOutPath, os.O_WRONLY)
wg.Add(1)
go opener(&ptout, *ptOutPath, os.O_WRONLY)
wg.Wait()
conv := otr.Conversation{PrivateKey: &prv, FragmentSize: MaxMsgSize}
exited := make(chan struct{})
go func() {
scanner := bufio.NewScanner(ptin)
var err error
var msg []byte
var msgs [][]byte
var t string
for scanner.Scan() {
t = scanner.Text()
if strings.HasPrefix(t, OTRStart) {
ctout.Write(append([]byte(otr.QueryMessage), '\n'))
continue
} else if t == OTRStop {
msgs = conv.End()
} else if strings.HasPrefix(t, OTRSMP) {
ss := strings.SplitN(t, " ", 3)
var question string
if len(ss) == 1 {
log.Println("Invalid SMP usage")
continue
} else if len(ss) == 3 {
question = ss[2]
}
msgs, err = conv.Authenticate(question, []byte(ss[1]))
if err != nil {
log.Println("Error during authentication:", err)
continue
}
} else {
msgs, err = conv.Send(scanner.Bytes())
if err != nil {
log.Println("Error during sending:", err)
continue
}
}
for _, msg = range msgs {
ctout.Write(append(msg, '\n'))
}
}
exited <- struct{}{}
}()
go func() {
scanner := bufio.NewScanner(ctin)
var got []byte
var msg []byte
var enc bool
var change otr.SecurityChange
var toSend [][]byte
var err error
for scanner.Scan() {
got, enc, change, toSend, err = conv.Receive(scanner.Bytes())
//.........这里部分代码省略.........