diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-06-24 23:45:27 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2025-09-15 22:16:23 +0200 |
| commit | 2eeee990f029779d8d1c2205b99a239bf87fbbe5 (patch) | |
| tree | 8a5402633b55a447f03e07f7f061318f0a5164a6 | |
| parent | 6fe97406c72dd95339e4045679507b709dbefae2 (diff) | |
Hash to a vector of bytes rather than an ASCII string.2758-safe-write
| -rwxr-xr-x | src/AS_DCP.h | 7 | ||||
| -rwxr-xr-x | src/AS_DCP_JP2K.cpp | 10 | ||||
| -rwxr-xr-x | src/AS_DCP_MPEG2.cpp | 6 | ||||
| -rwxr-xr-x | src/AS_DCP_internal.h | 6 | ||||
| -rw-r--r-- | src/KM_fileio.cpp | 34 | ||||
| -rwxr-xr-x | src/KM_fileio.h | 3 | ||||
| -rwxr-xr-x | src/h__Writer.cpp | 4 |
7 files changed, 24 insertions, 46 deletions
diff --git a/src/AS_DCP.h b/src/AS_DCP.h index acdf8c5..b332e1e 100755 --- a/src/AS_DCP.h +++ b/src/AS_DCP.h @@ -93,6 +93,7 @@ This project depends upon the following libraries: #include <string> #include <cstring> #include <list> +#include <vector> //-------------------------------------------------------------------------------- // common integer types @@ -782,7 +783,7 @@ namespace ASDCP { // argument is present, the essence is encrypted prior to writing. // Fails if the file is not open, is finalized, or an operating system // error occurs. - Result_t WriteFrame(const FrameBuffer&, AESEncContext* = 0, HMACContext* = 0, std::string* hash = 0); + Result_t WriteFrame(const FrameBuffer&, AESEncContext* = 0, HMACContext* = 0, std::vector<uint8_t>* hash = 0); Result_t FakeWriteFrame(int size, FrameType_t frame_type, bool gop_start, bool closed_gop, ui8_t temporal_offset); @@ -1279,7 +1280,7 @@ namespace ASDCP { // A MD5 hash of the data that we write is written to hash if it is not 0 // Fails if the file is not open, is finalized, or an operating system // error occurs. - Result_t WriteFrame(const FrameBuffer&, AESEncContext* = 0, HMACContext* = 0, std::string* hash = 0); + Result_t WriteFrame(const FrameBuffer&, AESEncContext* = 0, HMACContext* = 0, std::vector<uint8_t>* hash = 0); Result_t FakeWriteFrame(int size); @@ -1398,7 +1399,7 @@ namespace ASDCP { // RESULT_SPHASE will be returned if phase is reversed. The first frame // written must be left eye. Result_t WriteFrame(const FrameBuffer&, StereoscopicPhase_t phase, - AESEncContext* = 0, HMACContext* = 0, std::string* hash = 0); + AESEncContext* = 0, HMACContext* = 0, std::vector<uint8_t>* hash = 0); Result_t FakeWriteFrame(int size, StereoscopicPhase_t phase); diff --git a/src/AS_DCP_JP2K.cpp b/src/AS_DCP_JP2K.cpp index 33bde17..7468cd1 100755 --- a/src/AS_DCP_JP2K.cpp +++ b/src/AS_DCP_JP2K.cpp @@ -1161,7 +1161,7 @@ public: Result_t OpenWrite(const std::string&, EssenceType_t type, ui32_t HeaderSize, bool); Result_t SetSourceStream(const PictureDescriptor&, const std::string& label, ASDCP::Rational LocalEditRate = ASDCP::Rational(0,0)); - Result_t WriteFrame(const JP2K::FrameBuffer&, bool add_index, AESEncContext*, HMACContext*, std::string* hash = 0); + Result_t WriteFrame(const JP2K::FrameBuffer&, bool add_index, AESEncContext*, HMACContext*, std::vector<uint8_t>* hash = 0); Result_t FakeWriteFrame(int size, bool add_index); Result_t Finalize(); }; @@ -1269,7 +1269,7 @@ lh__Writer::SetSourceStream(const PictureDescriptor& PDesc, const std::string& l // ASDCP::Result_t lh__Writer::WriteFrame(const JP2K::FrameBuffer& FrameBuf, bool add_index, - AESEncContext* Ctx, HMACContext* HMAC, std::string* hash) + AESEncContext* Ctx, HMACContext* HMAC, std::vector<uint8_t>* hash) { Result_t result = RESULT_OK; @@ -1430,7 +1430,7 @@ ASDCP::JP2K::MXFWriter::OpenWrite(const std::string& filename, const WriterInfo& // Fails if the file is not open, is finalized, or an operating system // error occurs. ASDCP::Result_t -ASDCP::JP2K::MXFWriter::WriteFrame(const FrameBuffer& FrameBuf, AESEncContext* Ctx, HMACContext* HMAC, std::string* hash) +ASDCP::JP2K::MXFWriter::WriteFrame(const FrameBuffer& FrameBuf, AESEncContext* Ctx, HMACContext* HMAC, std::vector<uint8_t>* hash) { if ( m_Writer.empty() ) return RESULT_INIT; @@ -1478,7 +1478,7 @@ public: // Result_t WriteFrame(const FrameBuffer& FrameBuf, StereoscopicPhase_t phase, - AESEncContext* Ctx, HMACContext* HMAC, std::string* hash) + AESEncContext* Ctx, HMACContext* HMAC, std::vector<uint8_t>* hash) { if ( m_NextPhase != phase ) return RESULT_SPHASE; @@ -1667,7 +1667,7 @@ ASDCP::JP2K::MXFSWriter::WriteFrame(const SFrameBuffer& FrameBuf, AESEncContext* // error occurs. ASDCP::Result_t ASDCP::JP2K::MXFSWriter::WriteFrame(const FrameBuffer& FrameBuf, StereoscopicPhase_t phase, - AESEncContext* Ctx, HMACContext* HMAC, std::string* hash) + AESEncContext* Ctx, HMACContext* HMAC, std::vector<uint8_t>* hash) { if ( m_Writer.empty() ) return RESULT_INIT; diff --git a/src/AS_DCP_MPEG2.cpp b/src/AS_DCP_MPEG2.cpp index 10a25d1..8075960 100755 --- a/src/AS_DCP_MPEG2.cpp +++ b/src/AS_DCP_MPEG2.cpp @@ -544,7 +544,7 @@ public: Result_t OpenWrite(const std::string&, ui32_t HeaderSize, bool overwrite = false); Result_t SetSourceStream(const VideoDescriptor&); - Result_t WriteFrame(const FrameBuffer&, AESEncContext* = 0, HMACContext* = 0, std::string* hash = 0); + Result_t WriteFrame(const FrameBuffer&, AESEncContext* = 0, HMACContext* = 0, std::vector<uint8_t>* hash = 0); Result_t FakeWriteFrame(int size, FrameType_t frame_type, bool gop_start, bool closed_gop, ui8_t temporal_offset); Result_t Finalize(); }; @@ -616,7 +616,7 @@ ASDCP::MPEG2::MXFWriter::h__Writer::SetSourceStream(const VideoDescriptor& VDesc // ASDCP::Result_t ASDCP::MPEG2::MXFWriter::h__Writer::WriteFrame(const FrameBuffer& FrameBuf, AESEncContext* Ctx, - HMACContext* HMAC, std::string* hash) + HMACContext* HMAC, std::vector<uint8_t>* hash) { Result_t result = RESULT_OK; @@ -828,7 +828,7 @@ ASDCP::MPEG2::MXFWriter::OpenWrite(const std::string& filename, const WriterInfo // Fails if the file is not open, is finalized, or an operating system // error occurs. ASDCP::Result_t -ASDCP::MPEG2::MXFWriter::WriteFrame(const FrameBuffer& FrameBuf, AESEncContext* Ctx, HMACContext* HMAC, std::string* hash) +ASDCP::MPEG2::MXFWriter::WriteFrame(const FrameBuffer& FrameBuf, AESEncContext* Ctx, HMACContext* HMAC, std::vector<uint8_t>* hash) { if ( m_Writer.empty() ) return RESULT_INIT; diff --git a/src/AS_DCP_internal.h b/src/AS_DCP_internal.h index 9d3fee9..98d0510 100755 --- a/src/AS_DCP_internal.h +++ b/src/AS_DCP_internal.h @@ -183,7 +183,7 @@ extern MXF::RIP *g_RIP; const ASDCP::WriterInfo& Info, ASDCP::FrameBuffer& CtFrameBuf, ui32_t& FramesWritten, ui64_t & StreamOffset, const ASDCP::FrameBuffer& FrameBuf, const byte_t* EssenceUL, const ui32_t& MinEssenceElementBerLength, - AESEncContext* Ctx, HMACContext* HMAC, std::string* hash = 0); + AESEncContext* Ctx, HMACContext* HMAC, std::vector<uint8_t>* hash = 0); // class KLReader : public ASDCP::KLVPacket @@ -859,7 +859,7 @@ extern MXF::RIP *g_RIP; } Result_t AddDmsGenericPartUtf8Text(const ASDCP::FrameBuffer& frame_buffer, - ASDCP::AESEncContext* enc = 0, ASDCP::HMACContext* hmac = 0, + ASDCP::AESEncContext* enc = 0, ASDCP::HMACContext* hmac = 0, const std::string& trackDescription = "Descriptive Track", const std::string& dataDescription = "") { @@ -965,7 +965,7 @@ extern MXF::RIP *g_RIP; Result_t CreateBodyPart(const MXF::Rational& EditRate, ui32_t BytesPerEditUnit = 0); Result_t WriteEKLVPacket(const ASDCP::FrameBuffer& FrameBuf,const byte_t* EssenceUL, const ui32_t& MinEssenceElementBerLength, - AESEncContext* Ctx, HMACContext* HMAC, std::string* hash = 0); + AESEncContext* Ctx, HMACContext* HMAC, std::vector<uint8_t>* hash = 0); Result_t FakeWriteEKLVPacket(int size); Result_t WriteASDCPFooter(); }; diff --git a/src/KM_fileio.cpp b/src/KM_fileio.cpp index de3948a..bc4624a 100644 --- a/src/KM_fileio.cpp +++ b/src/KM_fileio.cpp @@ -34,6 +34,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <fcntl.h> #include <assert.h> +#include <vector> #ifdef KM_WIN32 #include <direct.h> @@ -786,39 +787,14 @@ Kumu::FileWriter::MaybeHash(void const * data, int size) } } -std::string +std::vector<uint8_t> Kumu::FileWriter::StopHashing() { m_Hashing = false; - unsigned char digest[MD5_DIGEST_LENGTH]; - MD5_Final (digest, &m_MD5Context); - - char buffer[33]; - snprintf( - buffer, - 33, - // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 - "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - digest[0], - digest[1], - digest[2], - digest[3], - digest[4], - digest[5], - digest[6], - digest[7], - digest[8], - digest[9], - digest[10], - digest[11], - digest[12], - digest[13], - digest[14], - digest[15] - ); - - return buffer; + std::vector<uint8_t> digest(MD5_DIGEST_LENGTH); + MD5_Final(digest.data(), &m_MD5Context); + return digest; } Kumu::FileReader::FileReader() diff --git a/src/KM_fileio.h b/src/KM_fileio.h index 38f7301..177d017 100755 --- a/src/KM_fileio.h +++ b/src/KM_fileio.h @@ -34,6 +34,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "KM_util.h" #include <string> +#include <vector> #include <openssl/md5.h> #ifdef KM_WIN32 @@ -405,7 +406,7 @@ namespace Kumu void StartHashing(); void MaybeHash(void const*, int); - std::string StopHashing(); + std::vector<uint8_t> StopHashing(); }; Result_t CreateDirectoriesInPath(const std::string& Path); diff --git a/src/h__Writer.cpp b/src/h__Writer.cpp index 4eaf72f..3736c12 100755 --- a/src/h__Writer.cpp +++ b/src/h__Writer.cpp @@ -320,7 +320,7 @@ ASDCP::h__ASDCPWriter::WriteASDCPHeader(const std::string& PackageLabel, const U Result_t ASDCP::h__ASDCPWriter::WriteEKLVPacket(const ASDCP::FrameBuffer& FrameBuf,const byte_t* EssenceUL, const ui32_t& MinEssenceElementBerLength, - AESEncContext* Ctx, HMACContext* HMAC, std::string* hash) + AESEncContext* Ctx, HMACContext* HMAC, std::vector<uint8_t>* hash) { return Write_EKLV_Packet(m_File, *m_Dict, m_HeaderPart, m_Info, m_CtFrameBuf, m_FramesWritten, m_StreamOffset, FrameBuf, EssenceUL, MinEssenceElementBerLength, @@ -393,7 +393,7 @@ ASDCP::Write_EKLV_Packet(Kumu::FileWriter& File, const ASDCP::Dictionary& Dict, const ASDCP::WriterInfo& Info, ASDCP::FrameBuffer& CtFrameBuf, ui32_t& FramesWritten, ui64_t & StreamOffset, const ASDCP::FrameBuffer& FrameBuf, const byte_t* EssenceUL, const ui32_t& MinEssenceElementBerLength, - AESEncContext* Ctx, HMACContext* HMAC, std::string* hash) + AESEncContext* Ctx, HMACContext* HMAC, std::vector<uint8_t>* hash) { Result_t result = RESULT_OK; IntegrityPack IntPack; |
