Source File
fingerprint.go
Belonging Package
github.com/pion/stun/v3
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>// SPDX-License-Identifier: MITpackage stunimport ()// FingerprintAttr represents FINGERPRINT attribute.//// RFC 5389 Section 15.5type FingerprintAttr struct{}// ErrFingerprintMismatch means that computed fingerprint differs from expected.var ErrFingerprintMismatch = errors.New("fingerprint check failed")// Fingerprint is shorthand for FingerprintAttr.//// Example://// m := New()// Fingerprint.AddTo(m)var Fingerprint FingerprintAttr //nolint:gochecknoglobalsconst (fingerprintXORValue uint32 = 0x5354554e //nolint:staticcheckfingerprintSize = 4 // 32 bit)// FingerprintValue returns CRC-32 of b XOR-ed by 0x5354554e.//// The value of the attribute is computed as the CRC-32 of the STUN message// up to (but excluding) the FINGERPRINT attribute itself, XOR'ed with// the 32-bit value 0x5354554e (the XOR helps in cases where an// application packet is also using CRC-32 in it).func ( []byte) uint32 {return crc32.ChecksumIEEE() ^ fingerprintXORValue // XOR}// AddTo adds fingerprint to message.func (FingerprintAttr) ( *Message) error {:= .Length// length in header should include size of fingerprint attribute.Length += fingerprintSize + attributeHeaderSize // increasing length.WriteLength() // writing Length to Raw:= make([]byte, fingerprintSize):= FingerprintValue(.Raw)bin.PutUint32(, ).Length =.Add(AttrFingerprint, )return nil}// Check reads fingerprint value from m and checks it, returning error if any.// Can return *AttrLengthErr, ErrAttributeNotFound, and *CRCMismatch.func (FingerprintAttr) ( *Message) error {, := .Get(AttrFingerprint)if != nil {return}if = CheckSize(AttrFingerprint, len(), fingerprintSize); != nil {return}:= bin.Uint32():= len(.Raw) - (fingerprintSize + attributeHeaderSize):= FingerprintValue(.Raw[:])return checkFingerprint(, )}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |