Chromium Code Reviews| Index: media/cast/cast_defines.h |
| diff --git a/media/cast/cast_defines.h b/media/cast/cast_defines.h |
| index f44e5fb82614a3ab20bea4e195952594ac571aeb..9bb8977905ef3685f61d943c1b18a213feb20b38 100644 |
| --- a/media/cast/cast_defines.h |
| +++ b/media/cast/cast_defines.h |
| @@ -46,6 +46,8 @@ const size_t kMinLengthOfRtcp = 8; |
| // Basic RTP header + cast header. |
| const size_t kMinLengthOfRtp = 12 + 6; |
| +const size_t kAesBlockSize = 16; |
| + |
| // Each uint16 represents one packet id within a cast frame. |
| typedef std::set<uint16> PacketIdSet; |
| // Each uint8 represents one cast frame. |
| @@ -130,6 +132,47 @@ inline base::TimeTicks ConvertNtpToTimeTicks(uint32 ntp_seconds, |
| return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch; |
| } |
| +inline char ConvertFromBase16Char(char base_16) { |
|
Alpha Left Google
2013/11/07 01:10:11
Don't do this. You should assume the key and IV ar
pwestin
2013/11/07 17:16:04
Moved to test app. I did find the base 64 but not
|
| + DCHECK((base_16 >= '0' && base_16 <= '9') || |
| + (base_16 >= 'a' && base_16 <= 'f') || |
| + (base_16 >= 'A' && base_16 <= 'F')); |
| + |
| + if (base_16 >= '0' && base_16 <= '9') { |
| + return base_16 - '0'; |
| + } |
| + if (base_16 >= 'a' && base_16 <= 'f') { |
| + return base_16 - 'a' + 10; |
| + } |
| + return base_16 - 'A' + 10; |
| +} |
| + |
| +inline std::string ConvertFromBase16String(std::string base_16) { |
| + std::string compressed; |
| + DCHECK(base_16.size() % 2 == 0) << "Must be a multiple of 2"; |
| + compressed.reserve(base_16.size() / 2); |
| + |
| + for (std::string::iterator it = base_16.begin(); it != base_16.end(); ++it) { |
| + char first_part = ConvertFromBase16Char(*it++); |
| + char second_part = ConvertFromBase16Char(*it); |
| + compressed.push_back((first_part << 4) + second_part); |
| + } |
| + return compressed; |
| +} |
| + |
| +inline std::string GetAesNounce(uint32 frame_id, const std::string& iv_mask) { |
| + std::string aes_ivec(kAesBlockSize, 0); |
| + |
| + aes_ivec[11] = frame_id & 0xff; |
| + aes_ivec[10] = (frame_id >> 8) & 0xff; |
| + aes_ivec[9] = (frame_id >> 16) & 0xff; |
| + aes_ivec[8] = (frame_id >> 24) & 0xff; |
| + |
| + for (size_t i = 0; i < kAesBlockSize; ++i) { |
| + aes_ivec[i] ^= iv_mask[i]; |
| + } |
| + return aes_ivec; |
| +} |
| + |
| } // namespace cast |
| } // namespace media |