-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmsg_auth_ch.go
More file actions
62 lines (51 loc) · 1.64 KB
/
msg_auth_ch.go
File metadata and controls
62 lines (51 loc) · 1.64 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2016 The btcsuite developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package wire
import (
"io"
)
// MsgAuthch authentication handshake message
type MsgAuthch struct {
Version int32
Length uint32
Challenge []byte
}
// Bsvdecode decodes r using the bitcoin protocol encoding into the receiver.
// This is part of the Message interface implementation.
func (msg *MsgAuthch) Bsvdecode(r io.Reader, pver uint32, _ MessageEncoding) error {
// Read stop hash
err := readElement(r, &msg.Version)
if err != nil {
return err
}
msg.Challenge, err = ReadVarBytes(r, pver, msg.MaxPayloadLength(pver), "challenge")
if err != nil {
return err
}
msg.Length = uint32(len(msg.Challenge))
return nil
}
// BsvEncode encodes the receiver to w using the bitcoin protocol encoding.
// This is part of the Message interface implementation.
func (msg *MsgAuthch) BsvEncode(w io.Writer, _ uint32, _ MessageEncoding) error {
return writeElements(w, msg.Version, msg.Length, msg.Challenge)
}
// Command returns the protocol command string for the message. This is part
// of the Message interface implementation.
func (msg *MsgAuthch) Command() string {
return CmdAuthch
}
// MaxPayloadLength returns the maximum length the payload can be for the
// receiver. This is part of the Message interface implementation.
func (msg *MsgAuthch) MaxPayloadLength(_ uint32) uint64 {
return 40
}
// NewMsgAuthch returns a new auth challenge message
func NewMsgAuthch(message string) *MsgAuthch {
return &MsgAuthch{
Version: 1,
Length: uint32(len(message)),
Challenge: []byte(message),
}
}