Skip to content

Commit fb02431

Browse files
committed
reduce diff
1 parent 8f658b6 commit fb02431

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

srtp_cipher_aead_aes_gcm.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,14 @@ func (s *srtpCipherAeadAesGcm) doEncryptRTP(dst []byte, header *rtp.Header, head
136136
rocInAuthTag bool, sameBuffer bool, payloadLen int, authPartLen int,
137137
) error {
138138
s.rtpIV = s.rtpInitializationVector(header, roc)
139+
encrypt := func(dst, plaintext []byte, headerLen int) error {
140+
s.srtpCipher.Seal(dst[headerLen:headerLen], s.rtpIV[:], plaintext[headerLen:], plaintext[:headerLen])
141+
142+
return nil
143+
}
144+
139145
switch {
140146
case s.useCryptex && header.Extension:
141-
encrypt := func(dst, plaintext []byte, headerLen int) error {
142-
s.srtpCipher.Seal(dst[headerLen:headerLen], s.rtpIV[:], plaintext[headerLen:], plaintext[:headerLen])
143-
144-
return nil
145-
}
146147
err := encryptCryptexRTP(dst, plaintext, sameBuffer, header, encrypt)
147148
if err != nil {
148149
return err
@@ -211,21 +212,20 @@ func (s *srtpCipherAeadAesGcm) doDecryptRTP(dst, ciphertext []byte, header *rtp.
211212
sameBuffer bool, nEnd int, authTagLen int,
212213
) error {
213214
s.rtpIV = s.rtpInitializationVector(header, roc)
215+
decrypt := func(dst, ciphertext []byte, headerLen int) error {
216+
_, err := s.srtpCipher.Open(dst[headerLen:headerLen], s.rtpIV[:], ciphertext[headerLen:nEnd], ciphertext[:headerLen])
217+
218+
return err
219+
}
220+
214221
switch {
215222
case isCryptexPacket(header):
216-
decrypt := func(dst, ciphertext []byte, headerLen int) error {
217-
_, err := s.srtpCipher.Open(dst[headerLen:headerLen], s.rtpIV[:], ciphertext[headerLen:nEnd], ciphertext[:headerLen])
218-
219-
return err
220-
}
221223
err := decryptCryptexRTP(dst, ciphertext, sameBuffer, header, headerLen, decrypt)
222224
if err != nil {
223225
return fmt.Errorf("%w: %w", ErrFailedToVerifyAuthTag, err)
224226
}
225227
case s.srtpEncrypted:
226-
_, err := s.srtpCipher.Open(
227-
dst[headerLen:headerLen], s.rtpIV[:], ciphertext[headerLen:nEnd], ciphertext[:headerLen])
228-
if err != nil {
228+
if err := decrypt(dst, ciphertext[:nEnd], headerLen); err != nil {
229229
return fmt.Errorf("%w: %w", ErrFailedToVerifyAuthTag, err)
230230
}
231231
// Copy the header unencrypted.

0 commit comments

Comments
 (0)