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