change_cipher_spec.go 962 B

123456789101112131415161718192021222324252627282930
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. package protocol
  4. // ChangeCipherSpec protocol exists to signal transitions in
  5. // ciphering strategies. The protocol consists of a single message,
  6. // which is encrypted and compressed under the current (not the pending)
  7. // connection state. The message consists of a single byte of value 1.
  8. // https://tools.ietf.org/html/rfc5246#section-7.1
  9. type ChangeCipherSpec struct{}
  10. // ContentType returns the ContentType of this content
  11. func (c ChangeCipherSpec) ContentType() ContentType {
  12. return ContentTypeChangeCipherSpec
  13. }
  14. // Marshal encodes the ChangeCipherSpec to binary
  15. func (c *ChangeCipherSpec) Marshal() ([]byte, error) {
  16. return []byte{0x01}, nil
  17. }
  18. // Unmarshal populates the ChangeCipherSpec from binary
  19. func (c *ChangeCipherSpec) Unmarshal(data []byte) error {
  20. if len(data) == 1 && data[0] == 0x01 {
  21. return nil
  22. }
  23. return errInvalidCipherSpec
  24. }