encryptLocalState is used to help encrypt local state before sending
(sendBuf []byte, streamLabel string)
| 1090 | |
| 1091 | // encryptLocalState is used to help encrypt local state before sending |
| 1092 | func (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 |
| 1121 | func (m *Memberlist) decryptRemoteState(bufConn io.Reader, streamLabel string) ([]byte, error) { |