util.go 863 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. package dtls
  4. func findMatchingSRTPProfile(a, b []SRTPProtectionProfile) (SRTPProtectionProfile, bool) {
  5. for _, aProfile := range a {
  6. for _, bProfile := range b {
  7. if aProfile == bProfile {
  8. return aProfile, true
  9. }
  10. }
  11. }
  12. return 0, false
  13. }
  14. func findMatchingCipherSuite(a, b []CipherSuite) (CipherSuite, bool) {
  15. for _, aSuite := range a {
  16. for _, bSuite := range b {
  17. if aSuite.ID() == bSuite.ID() {
  18. return aSuite, true
  19. }
  20. }
  21. }
  22. return nil, false
  23. }
  24. func splitBytes(bytes []byte, splitLen int) [][]byte {
  25. splitBytes := make([][]byte, 0)
  26. numBytes := len(bytes)
  27. for i := 0; i < numBytes; i += splitLen {
  28. j := i + splitLen
  29. if j > numBytes {
  30. j = numBytes
  31. }
  32. splitBytes = append(splitBytes, bytes[i:j])
  33. }
  34. return splitBytes
  35. }