From 9c5328621e3e115e7e840bf04496aafefdeb0827 Mon Sep 17 00:00:00 2001 From: Craig Edwards Date: Sat, 5 Oct 2024 13:09:26 +0000 Subject: [PATCH] refactor naming --- src/dpp/dave/codec_utils.cpp | 66 +++++++++++++++---------------- src/dpp/dave/codec_utils.h | 14 +++---- src/dpp/dave/decryptor.cpp | 16 ++++---- src/dpp/dave/encryptor.cpp | 18 ++++----- src/dpp/dave/encryptor.h | 6 +-- src/dpp/dave/frame_processors.cpp | 32 +++++++-------- src/dpp/dave/frame_processors.h | 44 ++++++++++----------- 7 files changed, 98 insertions(+), 98 deletions(-) diff --git a/src/dpp/dave/codec_utils.cpp b/src/dpp/dave/codec_utils.cpp index 632f62ba3c..f886b5f9fb 100755 --- a/src/dpp/dave/codec_utils.cpp +++ b/src/dpp/dave/codec_utils.cpp @@ -137,13 +137,13 @@ std::optional FindNextH26XNaluIndex(const uint8_t* buffe return std::nullopt; } -bool process_frame_opus(OutboundFrameProcessor& processor, array_view frame) +bool process_frame_opus(outbound_frame_processor& processor, array_view frame) { - processor.AddEncryptedBytes(frame.data(), frame.size()); + processor.add_encrypted_bytes(frame.data(), frame.size()); return true; } -bool process_frame_vp8(OutboundFrameProcessor& processor, array_view frame) +bool process_frame_vp8(outbound_frame_processor& processor, array_view frame) { constexpr uint8_t kVP8KeyFrameUnencryptedBytes = 10; constexpr uint8_t kVP8DeltaFrameUnencryptedBytes = 1; @@ -169,21 +169,21 @@ bool process_frame_vp8(OutboundFrameProcessor& processor, array_view frame) +bool process_frame_vp9(outbound_frame_processor& processor, array_view frame) { // payload descriptor is unencrypted in each packet // and includes all information the depacketizer needs - processor.AddEncryptedBytes(frame.data(), frame.size()); + processor.add_encrypted_bytes(frame.data(), frame.size()); return true; } -bool process_frame_h264(OutboundFrameProcessor& processor, array_view frame) +bool process_frame_h264(outbound_frame_processor& processor, array_view frame) { // minimize the amount of unencrypted header data for H264 depending on the NAL unit // type from WebRTC, see: src/modules/rtp_rtcp/source/rtp_format_h264.cc @@ -215,7 +215,7 @@ bool process_frame_h264(OutboundFrameProcessor& processor, array_view frame) +bool process_frame_h265(outbound_frame_processor& processor, array_view frame) { // minimize the amount of unencrypted header data for H265 depending on the NAL unit // type from WebRTC, see: src/modules/rtp_rtcp/source/rtp_format_h265.cc @@ -279,7 +279,7 @@ bool process_frame_h265(OutboundFrameProcessor& processor, array_view frame) +bool process_frame_av1(outbound_frame_processor& processor, array_view frame) { constexpr uint8_t kAv1ObuHeaderHasExtensionMask = 0b0'0000'100; constexpr uint8_t kAv1ObuHeaderHasSizeMask = 0b0'0000'010; @@ -382,11 +382,11 @@ bool process_frame_av1(OutboundFrameProcessor& processor, array_view frame) +bool validate_encrypted_frame(outbound_frame_processor& processor, array_view frame) { - auto codec = processor.GetCodec(); + auto codec = processor.get_codec(); if (codec != Codec::H264 && codec != Codec::H265) { return true; } @@ -418,7 +418,7 @@ bool validate_encrypted_frame(OutboundFrameProcessor& processor, array_view= 0, "Padding will overflow!"); constexpr size_t Padding = kH26XNaluShortStartSequenceSize - 1; - const auto& unencryptedRanges = processor.GetUnencryptedRanges(); + const auto& unencryptedRanges = processor.get_unencrypted_ranges(); // H264 and H265 ciphertexts cannot contain a 3 or 4 byte start code {0, 0, 1} // otherwise the packetizer gets confused diff --git a/src/dpp/dave/codec_utils.h b/src/dpp/dave/codec_utils.h index e85d79b8ac..ea517c35e0 100755 --- a/src/dpp/dave/codec_utils.h +++ b/src/dpp/dave/codec_utils.h @@ -30,14 +30,14 @@ namespace dpp::dave::codec_utils { -bool process_frame_opus(OutboundFrameProcessor & processor, array_view frame); -bool process_frame_vp8(OutboundFrameProcessor & processor, array_view frame); -bool process_frame_vp9(OutboundFrameProcessor & processor, array_view frame); -bool process_frame_h264(OutboundFrameProcessor & processor, array_view frame); -bool process_frame_h265(OutboundFrameProcessor & processor, array_view frame); -bool process_frame_av1(OutboundFrameProcessor & processor, array_view frame); +bool process_frame_opus(outbound_frame_processor & processor, array_view frame); +bool process_frame_vp8(outbound_frame_processor & processor, array_view frame); +bool process_frame_vp9(outbound_frame_processor & processor, array_view frame); +bool process_frame_h264(outbound_frame_processor & processor, array_view frame); +bool process_frame_h265(outbound_frame_processor & processor, array_view frame); +bool process_frame_av1(outbound_frame_processor & processor, array_view frame); -bool validate_encrypted_frame(OutboundFrameProcessor& processor, array_view frame); +bool validate_encrypted_frame(outbound_frame_processor& processor, array_view frame); } // namespace dpp::dave::codec_utils diff --git a/src/dpp/dave/decryptor.cpp b/src/dpp/dave/decryptor.cpp index 6b61c4fd08..da96b30100 100755 --- a/src/dpp/dave/decryptor.cpp +++ b/src/dpp/dave/decryptor.cpp @@ -95,11 +95,11 @@ size_t decryptor::decrypt(media_type mediaType, // Process the incoming frame // This will check whether it looks like a valid encrypted frame // and if so it will parse it into its different components - localFrame->ParseFrame(encryptedFrame); + localFrame->parse_frame(encryptedFrame); // If the frame is not encrypted and we can pass it through, do it bool canUsePassThrough = allowPassThroughUntil_ > start; - if (!localFrame->IsEncrypted() && canUsePassThrough) { + if (!localFrame->is_encrypted() && canUsePassThrough) { if (encryptedFrame.data() != frame.data()) { std::memcpy(frame.data(), encryptedFrame.data(), encryptedFrame.size()); } @@ -108,7 +108,7 @@ size_t decryptor::decrypt(media_type mediaType, } // If the frame is not encrypted and we can't pass it through, fail - if (!localFrame->IsEncrypted()) { + if (!localFrame->is_encrypted()) { DISCORD_LOG(LS_INFO) << "decrypt failed, frame is not encrypted and pass through is disabled"; stats_[mediaType].decrypt_failure++; @@ -129,7 +129,7 @@ size_t decryptor::decrypt(media_type mediaType, size_t bytesWritten = 0; if (success) { stats_[mediaType].decrypt_success++; - bytesWritten = localFrame->ReconstructFrame(frame); + bytesWritten = localFrame->reconstruct_frame(frame); } else { stats_[mediaType].decrypt_failure++; @@ -160,12 +160,12 @@ bool decryptor::decrypt_impl(aead_cipher_manager& cipher_manager, inbound_frame_processor& encryptedFrame, array_view frame) { - auto tag = encryptedFrame.GetTag(); - auto truncatedNonce = encryptedFrame.GetTruncatedNonce(); + auto tag = encryptedFrame.get_tag(); + auto truncatedNonce = encryptedFrame.get_truncated_nonce(); - auto authenticatedData = encryptedFrame.GetAuthenticatedData(); + auto authenticatedData = encryptedFrame.get_authenticated_data(); auto ciphertext = encryptedFrame.GetCiphertext(); - auto plaintext = encryptedFrame.GetPlaintext(); + auto plaintext = encryptedFrame.get_plaintext(); // expand the truncated nonce to the full sized one needed for decryption auto nonceBuffer = std::array(); diff --git a/src/dpp/dave/encryptor.cpp b/src/dpp/dave/encryptor.cpp index 2edd31c8eb..8937d0f7b7 100755 --- a/src/dpp/dave/encryptor.cpp +++ b/src/dpp/dave/encryptor.cpp @@ -92,13 +92,13 @@ int encryptor::encrypt(media_type mediaType, auto frameProcessor = get_or_create_frame_processor(); ScopeExit cleanup([&] { return_frame_processor(std::move(frameProcessor)); }); - frameProcessor->ProcessFrame(frame, codec); + frameProcessor->process_frame(frame, codec); - const auto& unencryptedBytes = frameProcessor->GetUnencryptedBytes(); - const auto& encryptedBytes = frameProcessor->GetEncryptedBytes(); - auto& ciphertextBytes = frameProcessor->GetCiphertextBytes(); + const auto& unencryptedBytes = frameProcessor->get_unencrypted_bytes(); + const auto& encryptedBytes = frameProcessor->get_encrypted_bytes(); + auto& ciphertextBytes = frameProcessor->get_ciphertext_bytes(); - const auto& unencryptedRanges = frameProcessor->GetUnencryptedRanges(); + const auto& unencryptedRanges = frameProcessor->get_unencrypted_ranges(); auto unencryptedRangesSize = UnencryptedRangesSize(unencryptedRanges); auto additionalData = make_array_view(unencryptedBytes.data(), unencryptedBytes.size()); @@ -151,7 +151,7 @@ int encryptor::encrypt(media_type mediaType, break; } - auto reconstructedFrameSize = frameProcessor->ReconstructFrame(encryptedFrame); + auto reconstructedFrameSize = frameProcessor->reconstruct_frame(encryptedFrame); assert(reconstructedFrameSize == frameSize && "Failed to reconstruct frame"); auto nonceSize = Leb128Size(truncatedNonce); @@ -262,18 +262,18 @@ Codec encryptor::codec_for_ssrc(uint32_t ssrc) } } -std::unique_ptr encryptor::get_or_create_frame_processor() +std::unique_ptr encryptor::get_or_create_frame_processor() { std::lock_guard lock(frameProcessorsMutex_); if (frameProcessors_.empty()) { - return std::make_unique(); + return std::make_unique(); } auto frameProcessor = std::move(frameProcessors_.back()); frameProcessors_.pop_back(); return frameProcessor; } -void encryptor::return_frame_processor(std::unique_ptr frameProcessor) +void encryptor::return_frame_processor(std::unique_ptr frameProcessor) { std::lock_guard lock(frameProcessorsMutex_); frameProcessors_.push_back(std::move(frameProcessor)); diff --git a/src/dpp/dave/encryptor.h b/src/dpp/dave/encryptor.h index 3837f4e1ba..0adc0617e4 100755 --- a/src/dpp/dave/encryptor.h +++ b/src/dpp/dave/encryptor.h @@ -82,8 +82,8 @@ class encryptor { }; private: - std::unique_ptr get_or_create_frame_processor(); - void return_frame_processor(std::unique_ptr frameProcessor); + std::unique_ptr get_or_create_frame_processor(); + void return_frame_processor(std::unique_ptr frameProcessor); using cryptor_and_nonce = std::pair, truncated_sync_nonce>; cryptor_and_nonce get_next_cryptor_and_nonce(); @@ -99,7 +99,7 @@ class encryptor { truncated_sync_nonce truncatedNonce_{0}; std::mutex frameProcessorsMutex_; - std::vector> frameProcessors_; + std::vector> frameProcessors_; using SsrcCodecPair = std::pair; std::vector ssrcCodecPairs_; diff --git a/src/dpp/dave/frame_processors.cpp b/src/dpp/dave/frame_processors.cpp index 66d9f121c8..9e313a2be3 100755 --- a/src/dpp/dave/frame_processors.cpp +++ b/src/dpp/dave/frame_processors.cpp @@ -183,7 +183,7 @@ size_t Reconstruct(Ranges ranges, return frameIndex; } -void inbound_frame_processor::Clear() +void inbound_frame_processor::clear() { isEncrypted_ = false; originalSize_ = 0; @@ -194,9 +194,9 @@ void inbound_frame_processor::Clear() plaintext_.clear(); } -void inbound_frame_processor::ParseFrame(array_view frame) +void inbound_frame_processor::parse_frame(array_view frame) { - Clear(); + clear(); constexpr auto MinSupplementalBytesSize = AES_GCM_127_TRUNCATED_TAG_BYTES + sizeof(supplemental_bytes_size) + sizeof(magic_marker); @@ -275,16 +275,16 @@ void inbound_frame_processor::ParseFrame(array_view frame) auto encryptedBytes = range.offset - frameIndex; if (encryptedBytes > 0) { assert(frameIndex + encryptedBytes <= frame.size()); - AddCiphertextBytes(frame.data() + frameIndex, encryptedBytes); + add_ciphertext_bytes(frame.data() + frameIndex, encryptedBytes); } assert(range.offset + range.size <= frame.size()); - AddAuthenticatedBytes(frame.data() + range.offset, range.size); + add_authenticated_bytes(frame.data() + range.offset, range.size); frameIndex = range.offset + range.size; } auto actualFrameSize = frame.size() - supplementalBytesSize; if (frameIndex < actualFrameSize) { - AddCiphertextBytes(frame.data() + frameIndex, actualFrameSize - frameIndex); + add_ciphertext_bytes(frame.data() + frameIndex, actualFrameSize - frameIndex); } // Make sure the plaintext buffer is the same size as the ciphertext buffer @@ -295,7 +295,7 @@ void inbound_frame_processor::ParseFrame(array_view frame) isEncrypted_ = true; } -size_t inbound_frame_processor::ReconstructFrame(array_view frame) const +size_t inbound_frame_processor::reconstruct_frame(array_view frame) const { if (!isEncrypted_) { DISCORD_LOG(LS_WARNING) << "Cannot reconstruct an invalid encrypted frame"; @@ -310,19 +310,19 @@ size_t inbound_frame_processor::ReconstructFrame(array_view frame) cons return Reconstruct(unencryptedRanges_, authenticated_, plaintext_, frame); } -void inbound_frame_processor::AddAuthenticatedBytes(const uint8_t* data, size_t size) +void inbound_frame_processor::add_authenticated_bytes(const uint8_t* data, size_t size) { authenticated_.resize(authenticated_.size() + size); memcpy(authenticated_.data() + authenticated_.size() - size, data, size); } -void inbound_frame_processor::AddCiphertextBytes(const uint8_t* data, size_t size) +void inbound_frame_processor::add_ciphertext_bytes(const uint8_t* data, size_t size) { ciphertext_.resize(ciphertext_.size() + size); memcpy(ciphertext_.data() + ciphertext_.size() - size, data, size); } -void OutboundFrameProcessor::Reset() +void outbound_frame_processor::reset() { codec_ = Codec::Unknown; frameIndex_ = 0; @@ -331,9 +331,9 @@ void OutboundFrameProcessor::Reset() unencryptedRanges_.clear(); } -void OutboundFrameProcessor::ProcessFrame(array_view frame, Codec codec) +void outbound_frame_processor::process_frame(array_view frame, Codec codec) { - Reset(); + reset(); codec_ = codec; unencryptedBytes_.reserve(frame.size()); @@ -369,13 +369,13 @@ void OutboundFrameProcessor::ProcessFrame(array_view frame, Codec unencryptedBytes_.clear(); encryptedBytes_.clear(); unencryptedRanges_.clear(); - AddEncryptedBytes(frame.data(), frame.size()); + add_encrypted_bytes(frame.data(), frame.size()); } ciphertextBytes_.resize(encryptedBytes_.size()); } -size_t OutboundFrameProcessor::ReconstructFrame(array_view frame) +size_t outbound_frame_processor::reconstruct_frame(array_view frame) { if (unencryptedBytes_.size() + ciphertextBytes_.size() > frame.size()) { DISCORD_LOG(LS_WARNING) << "Frame is too small to contain the encrypted frame"; @@ -385,7 +385,7 @@ size_t OutboundFrameProcessor::ReconstructFrame(array_view frame) return Reconstruct(unencryptedRanges_, unencryptedBytes_, ciphertextBytes_, frame); } -void OutboundFrameProcessor::AddUnencryptedBytes(const uint8_t* bytes, size_t size) +void outbound_frame_processor::add_unencrypted_bytes(const uint8_t* bytes, size_t size) { if (!unencryptedRanges_.empty() && unencryptedRanges_.back().offset + unencryptedRanges_.back().size == frameIndex_) { @@ -402,7 +402,7 @@ void OutboundFrameProcessor::AddUnencryptedBytes(const uint8_t* bytes, size_t si frameIndex_ += size; } -void OutboundFrameProcessor::AddEncryptedBytes(const uint8_t* bytes, size_t size) +void outbound_frame_processor::add_encrypted_bytes(const uint8_t* bytes, size_t size) { encryptedBytes_.resize(encryptedBytes_.size() + size); memcpy(encryptedBytes_.data() + encryptedBytes_.size() - size, bytes, size); diff --git a/src/dpp/dave/frame_processors.h b/src/dpp/dave/frame_processors.h index d0fa8d829b..9a5bb63d19 100755 --- a/src/dpp/dave/frame_processors.h +++ b/src/dpp/dave/frame_processors.h @@ -50,16 +50,16 @@ bool ValidateUnencryptedRanges(const Ranges& unencryptedRanges, size_t frameSize class inbound_frame_processor { public: - void ParseFrame(array_view frame); - size_t ReconstructFrame(array_view frame) const; + void parse_frame(array_view frame); + [[nodiscard]] size_t reconstruct_frame(array_view frame) const; - bool IsEncrypted() const { return isEncrypted_; } - size_t Size() const { return originalSize_; } - void Clear(); + [[nodiscard]] bool is_encrypted() const { return isEncrypted_; } + [[nodiscard]] size_t size() const { return originalSize_; } + void clear(); - array_view GetTag() const { return tag_; } - truncated_sync_nonce GetTruncatedNonce() const { return truncatedNonce_; } - array_view GetAuthenticatedData() const + [[nodiscard]] array_view get_tag() const { return tag_; } + [[nodiscard]] truncated_sync_nonce get_truncated_nonce() const { return truncatedNonce_; } + array_view get_authenticated_data() const { return make_array_view(authenticated_.data(), authenticated_.size()); } @@ -67,11 +67,11 @@ class inbound_frame_processor { { return make_array_view(ciphertext_.data(), ciphertext_.size()); } - array_view GetPlaintext() { return make_array_view(plaintext_); } + array_view get_plaintext() { return make_array_view(plaintext_); } private: - void AddAuthenticatedBytes(const uint8_t* data, size_t size); - void AddCiphertextBytes(const uint8_t* data, size_t size); + void add_authenticated_bytes(const uint8_t* data, size_t size); + void add_ciphertext_bytes(const uint8_t* data, size_t size); bool isEncrypted_{false}; size_t originalSize_{0}; @@ -83,20 +83,20 @@ class inbound_frame_processor { std::vector plaintext_; }; -class OutboundFrameProcessor { +class outbound_frame_processor { public: - void ProcessFrame(array_view frame, Codec codec); - size_t ReconstructFrame(array_view frame); + void process_frame(array_view frame, Codec codec); + size_t reconstruct_frame(array_view frame); - Codec GetCodec() const { return codec_; } - const std::vector& GetUnencryptedBytes() const { return unencryptedBytes_; } - const std::vector& GetEncryptedBytes() const { return encryptedBytes_; } - std::vector& GetCiphertextBytes() { return ciphertextBytes_; } - const Ranges& GetUnencryptedRanges() const { return unencryptedRanges_; } + Codec get_codec() const { return codec_; } + [[nodiscard]] const std::vector& get_unencrypted_bytes() const { return unencryptedBytes_; } + [[nodiscard]] const std::vector& get_encrypted_bytes() const { return encryptedBytes_; } + [[nodiscard]] std::vector& get_ciphertext_bytes() { return ciphertextBytes_; } + [[nodiscard]] const Ranges& get_unencrypted_ranges() const { return unencryptedRanges_; } - void Reset(); - void AddUnencryptedBytes(const uint8_t* bytes, size_t size); - void AddEncryptedBytes(const uint8_t* bytes, size_t size); + void reset(); + void add_unencrypted_bytes(const uint8_t* bytes, size_t size); + void add_encrypted_bytes(const uint8_t* bytes, size_t size); private: Codec codec_{Codec::Unknown};