diff options
| author | John Hurst <jhurst@cinecert.com> | 2021-08-26 20:43:24 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-26 20:43:24 -0700 |
| commit | 53e27f364c39cd70e34c05aeab4afcbeaf116b49 (patch) | |
| tree | fce9f1483259c402e569a45340faf75c3317a13a /src | |
| parent | b8c87905046423d7f04e9103ffb321a4d23870eb (diff) | |
| parent | 9c6e1bc188987558e64f72f1561749ccd20b5379 (diff) | |
Merge pull request #11 from DolbyLaboratories/dolby/atmos_storage/asdcplib_integration/dont_export_symbols
Do not export symbols on definitions in cpp. (moved functions and classes to an unnamed namespace and made variables static)
Diffstat (limited to 'src')
| -rw-r--r-- | src/ACES_Sequence_Parser.cpp | 78 | ||||
| -rwxr-xr-x | src/KM_prng.cpp | 153 | ||||
| -rw-r--r-- | src/KM_xml.cpp | 27 | ||||
| -rw-r--r-- | src/ST2052_TextParser.cpp | 2 | ||||
| -rw-r--r-- | src/TimedText_Parser.cpp | 51 |
5 files changed, 157 insertions, 154 deletions
diff --git a/src/ACES_Sequence_Parser.cpp b/src/ACES_Sequence_Parser.cpp index 655da1f..95887a0 100644 --- a/src/ACES_Sequence_Parser.cpp +++ b/src/ACES_Sequence_Parser.cpp @@ -32,57 +32,57 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <assert.h> #include <KM_log.h> - using Kumu::DefaultLogSink; +namespace { + class FileList : public std::list<std::string> + { + std::string m_DirName; -class FileList : public std::list<std::string> -{ - std::string m_DirName; - -public: - FileList() {} - ~FileList() {} + public: + FileList() {} + ~FileList() {} - const FileList& operator=(const std::list<std::string>& pathlist) - { - std::list<std::string>::const_iterator i; - for(i = pathlist.begin(); i != pathlist.end(); i++) - push_back(*i); - return *this; - } + const FileList& operator=(const std::list<std::string>& pathlist) + { + std::list<std::string>::const_iterator i; + for(i = pathlist.begin(); i != pathlist.end(); i++) + push_back(*i); + return *this; + } - // - ASDCP::Result_t InitFromDirectory(const std::string& path) - { - char next_file[Kumu::MaxFilePath]; - Kumu::DirScanner Scanner; + // + ASDCP::Result_t InitFromDirectory(const std::string& path) + { + char next_file[Kumu::MaxFilePath]; + Kumu::DirScanner Scanner; - ASDCP::Result_t result = Scanner.Open(path); + ASDCP::Result_t result = Scanner.Open(path); - if(ASDCP_SUCCESS(result)) - { - m_DirName = path; + if(ASDCP_SUCCESS(result)) + { + m_DirName = path; - while(ASDCP_SUCCESS(Scanner.GetNext(next_file))) - { - if(next_file[0] == '.') // no hidden files or internal links - continue; + while(ASDCP_SUCCESS(Scanner.GetNext(next_file))) + { + if(next_file[0] == '.') // no hidden files or internal links + continue; - std::string Str(m_DirName); - Str += "/"; - Str += next_file; + std::string Str(m_DirName); + Str += "/"; + Str += next_file; - if(!Kumu::PathIsDirectory(Str)) - push_back(Str); - } + if(!Kumu::PathIsDirectory(Str)) + push_back(Str); + } - sort(); - } + sort(); + } - return result; - } -}; + return result; + } + }; +} class AS_02::ACES::SequenceParser::h__SequenceParser diff --git a/src/KM_prng.cpp b/src/KM_prng.cpp index f40d846..f9ec0c0 100755 --- a/src/KM_prng.cpp +++ b/src/KM_prng.cpp @@ -50,7 +50,7 @@ using namespace Kumu; # include <wincrypt.h> #else // KM_WIN32 # include <KM_fileio.h> -const char* DEV_URANDOM = "/dev/urandom"; +static const char* DEV_URANDOM = "/dev/urandom"; #endif // KM_WIN32 @@ -59,94 +59,95 @@ const ui32_t RNG_KEY_SIZE_BITS = 256UL; const ui32_t RNG_BLOCK_SIZE = AES_BLOCKLEN; const ui32_t MAX_SEQUENCE_LEN = 0x00040000UL; +namespace{ + // internal implementation class + class h__RNG + { + KM_NO_COPY_CONSTRUCT(h__RNG); -// internal implementation class -class h__RNG -{ - KM_NO_COPY_CONSTRUCT(h__RNG); - -public: - AES_ctx m_Context; - byte_t m_ctr_buf[RNG_BLOCK_SIZE]; - Mutex m_Lock; + public: + AES_ctx m_Context; + byte_t m_ctr_buf[RNG_BLOCK_SIZE]; + Mutex m_Lock; - h__RNG() - { - memset(m_ctr_buf, 0, RNG_BLOCK_SIZE); - byte_t rng_key[RNG_KEY_SIZE]; + h__RNG() + { + memset(m_ctr_buf, 0, RNG_BLOCK_SIZE); + byte_t rng_key[RNG_KEY_SIZE]; - { // this block scopes the following AutoMutex so that it will be - // released before the call to set_key() below. - AutoMutex Lock(m_Lock); + { // this block scopes the following AutoMutex so that it will be + // released before the call to set_key() below. + AutoMutex Lock(m_Lock); -#ifdef KM_WIN32 - HCRYPTPROV hProvider = 0; - CryptAcquireContext(&hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); - CryptGenRandom(hProvider, RNG_KEY_SIZE, rng_key); -#else // KM_WIN32 - // on POSIX systems we simply read some seed from /dev/urandom - FileReader URandom; + #ifdef KM_WIN32 + HCRYPTPROV hProvider = 0; + CryptAcquireContext(&hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT); + CryptGenRandom(hProvider, RNG_KEY_SIZE, rng_key); + #else // KM_WIN32 + // on POSIX systems we simply read some seed from /dev/urandom + FileReader URandom; - Result_t result = URandom.OpenRead(DEV_URANDOM); + Result_t result = URandom.OpenRead(DEV_URANDOM); - if ( KM_SUCCESS(result) ) - { - ui32_t read_count; - result = URandom.Read(rng_key, RNG_KEY_SIZE, &read_count); - } + if ( KM_SUCCESS(result) ) + { + ui32_t read_count; + result = URandom.Read(rng_key, RNG_KEY_SIZE, &read_count); + } - if ( KM_FAILURE(result) ) - DefaultLogSink().Error("Error opening random device: %s\n", DEV_URANDOM); + if ( KM_FAILURE(result) ) + DefaultLogSink().Error("Error opening random device: %s\n", DEV_URANDOM); -#endif // KM_WIN32 - } // end AutoMutex context + #endif // KM_WIN32 + } // end AutoMutex context - set_key(rng_key); - } - - // - void - set_key(const byte_t* key_fodder) - { - assert(key_fodder); - byte_t sha_buf[20]; - SHA1_CTX SHA; - SHA1_Init(&SHA); - - SHA1_Update(&SHA, (byte_t*)&m_Context, sizeof(m_Context)); - SHA1_Update(&SHA, key_fodder, RNG_KEY_SIZE); - SHA1_Final(sha_buf, &SHA); - - AutoMutex Lock(m_Lock); - AES_init_ctx(&m_Context, sha_buf); - *(ui32_t*)(m_ctr_buf + 12) = 1; - } - - // - void - fill_rand(byte_t* buf, ui32_t len) - { - assert(len <= MAX_SEQUENCE_LEN); - ui32_t gen_count = 0; - AutoMutex Lock(m_Lock); - - while ( gen_count + RNG_BLOCK_SIZE <= len ) + set_key(rng_key); + } + + // + void + set_key(const byte_t* key_fodder) { - memcpy(buf + gen_count, m_ctr_buf, RNG_BLOCK_SIZE); - AES_encrypt(&m_Context, buf + gen_count); - *(ui32_t*)(m_ctr_buf + 12) += 1; - gen_count += RNG_BLOCK_SIZE; + assert(key_fodder); + byte_t sha_buf[20]; + SHA1_CTX SHA; + SHA1_Init(&SHA); + + SHA1_Update(&SHA, (byte_t*)&m_Context, sizeof(m_Context)); + SHA1_Update(&SHA, key_fodder, RNG_KEY_SIZE); + SHA1_Final(sha_buf, &SHA); + + AutoMutex Lock(m_Lock); + AES_init_ctx(&m_Context, sha_buf); + *(ui32_t*)(m_ctr_buf + 12) = 1; } - - if ( len != gen_count ) // partial count needed? + + // + void + fill_rand(byte_t* buf, ui32_t len) { - byte_t tmp[RNG_BLOCK_SIZE]; - memcpy(tmp, m_ctr_buf, RNG_BLOCK_SIZE); - AES_encrypt(&m_Context, tmp); - memcpy(buf + gen_count, tmp, len - gen_count); + assert(len <= MAX_SEQUENCE_LEN); + ui32_t gen_count = 0; + AutoMutex Lock(m_Lock); + + while ( gen_count + RNG_BLOCK_SIZE <= len ) + { + memcpy(buf + gen_count, m_ctr_buf, RNG_BLOCK_SIZE); + AES_encrypt(&m_Context, buf + gen_count); + *(ui32_t*)(m_ctr_buf + 12) += 1; + gen_count += RNG_BLOCK_SIZE; + } + + if ( len != gen_count ) // partial count needed? + { + byte_t tmp[RNG_BLOCK_SIZE]; + memcpy(tmp, m_ctr_buf, RNG_BLOCK_SIZE); + AES_encrypt(&m_Context, tmp); + memcpy(buf + gen_count, tmp, len - gen_count); + } } - } -}; + }; +} static h__RNG* s_RNG = 0; diff --git a/src/KM_xml.cpp b/src/KM_xml.cpp index 5037391..73ff8b5 100644 --- a/src/KM_xml.cpp +++ b/src/KM_xml.cpp @@ -74,20 +74,21 @@ extern "C" using namespace Kumu; - -class ns_map : public std::map<std::string, XMLNamespace*> -{ -public: - ~ns_map() +namespace{ + class ns_map : public std::map<std::string, XMLNamespace*> { - while ( ! empty() ) - { - ns_map::iterator ni = begin(); - delete ni->second; - erase(ni); - } - } -}; + public: + ~ns_map() + { + while ( ! empty() ) + { + ns_map::iterator ni = begin(); + delete ni->second; + erase(ni); + } + } + }; +} Kumu::XMLElement::XMLElement(const char* name) : m_Namespace(0), m_NamespaceOwner(0) diff --git a/src/ST2052_TextParser.cpp b/src/ST2052_TextParser.cpp index 75c0e86..9dabfb7 100644 --- a/src/ST2052_TextParser.cpp +++ b/src/ST2052_TextParser.cpp @@ -38,7 +38,7 @@ using namespace ASDCP; using Kumu::DefaultLogSink; -const char* c_tt_namespace_name = "http://www.smpte-ra.org/schemas/2052-1/2010/smpte-tt"; +static const char* c_tt_namespace_name = "http://www.smpte-ra.org/schemas/2052-1/2010/smpte-tt"; //------------------------------------------------------------------------------------------ diff --git a/src/TimedText_Parser.cpp b/src/TimedText_Parser.cpp index 020baf3..d3eca72 100644 --- a/src/TimedText_Parser.cpp +++ b/src/TimedText_Parser.cpp @@ -39,7 +39,7 @@ using namespace ASDCP; using Kumu::DefaultLogSink; -const char* c_dcst_namespace_name = "http://www.smpte-ra.org/schemas/428-7/2007/DCST"; +static const char* c_dcst_namespace_name = "http://www.smpte-ra.org/schemas/428-7/2007/DCST"; //------------------------------------------------------------------------------------------ @@ -144,36 +144,37 @@ public: Result_t OpenRead(const std::string& xml_doc, const std::string& filename); Result_t ReadAncillaryResource(const byte_t* uuid, FrameBuffer& FrameBuf, const IResourceResolver& Resolver) const; }; +namespace { + // + bool + get_UUID_from_element(XMLElement* Element, UUID& ID) + { + assert(Element); + const char* p = Element->GetBody().c_str(); -// -bool -get_UUID_from_element(XMLElement* Element, UUID& ID) -{ - assert(Element); - const char* p = Element->GetBody().c_str(); + if ( strncmp(p, "urn:uuid:", 9) == 0 ) + { + p += 9; + } + + return ID.DecodeHex(p); + } - if ( strncmp(p, "urn:uuid:", 9) == 0 ) + // + bool + get_UUID_from_child_element(const char* name, XMLElement* Parent, UUID& outID) { - p += 9; - } - - return ID.DecodeHex(p); -} + assert(name); + assert(Parent); + XMLElement* Child = Parent->GetChildWithName(name); -// -bool -get_UUID_from_child_element(const char* name, XMLElement* Parent, UUID& outID) -{ - assert(name); - assert(Parent); - XMLElement* Child = Parent->GetChildWithName(name); + if ( Child == 0 ) + { + return false; + } - if ( Child == 0 ) - { - return false; + return get_UUID_from_element(Child, outID); } - - return get_UUID_from_element(Child, outID); } // |
