MCPcopy
hub / github.com/hashicorp/memberlist / encryptLocalState

Method encryptLocalState

net.go:1092–1118  ·  view source on GitHub ↗

encryptLocalState is used to help encrypt local state before sending

(sendBuf []byte, streamLabel string)

Source from the content-addressed store, hash-verified

1090
1091// encryptLocalState is used to help encrypt local state before sending
1092func (m *Memberlist) encryptLocalState(sendBuf []byte, streamLabel string) ([]byte, error) {
1093 var buf bytes.Buffer
1094
1095 // Write the encryptMsg byte
1096 buf.WriteByte(byte(encryptMsg))
1097
1098 // Write the size of the message
1099 sizeBuf := make([]byte, 4)
1100 encVsn := m.encryptionVersion()
1101 encLen := encryptedLength(encVsn, len(sendBuf))
1102 binary.BigEndian.PutUint32(sizeBuf, uint32(encLen))
1103 buf.Write(sizeBuf)
1104
1105 // Authenticated Data is:
1106 //
1107 // [messageType; byte] [messageLength; uint32] [stream_label; optional]
1108 //
1109 dataBytes := appendBytes(buf.Bytes()[:5], []byte(streamLabel))
1110
1111 // Write the encrypted cipher text to the buffer
1112 key := m.config.Keyring.GetPrimaryKey()
1113 err := encryptPayload(encVsn, key, sendBuf, dataBytes, &buf)
1114 if err != nil {
1115 return nil, err
1116 }
1117 return buf.Bytes(), nil
1118}
1119
1120// decryptRemoteState is used to help decrypt the remote state
1121func (m *Memberlist) decryptRemoteState(bufConn io.Reader, streamLabel string) ([]byte, error) {

Callers 2

rawSendMsgStreamMethod · 0.95
TestEncryptDecryptStateFunction · 0.80

Calls 6

encryptionVersionMethod · 0.95
encryptedLengthFunction · 0.85
appendBytesFunction · 0.85
encryptPayloadFunction · 0.85
WriteMethod · 0.80
GetPrimaryKeyMethod · 0.80

Tested by 1

TestEncryptDecryptStateFunction · 0.64