1111
1212namespace {
1313template <typename I, typename O> void to_little_endian (I in, O &out) {
14- for (std:: size_t i = 0 ; i < sizeof (in); ++i) {
14+ for (int i = 0 ; i < sizeof (in); ++i) {
1515 out[i] = in & 0xff ;
1616 in >>= 8 ;
1717 }
1818}
1919
2020template <typename I, typename O> void to_big_endian (I in, O &out) {
21- for (std:: size_t i = sizeof (in) - 1 ; i >= 0 ; --i) {
21+ for (int i = sizeof (in) - 1 ; i >= 0 ; --i) {
2222 out[i] = in & 0xff ;
2323 in >>= 8 ;
2424 }
@@ -50,12 +50,12 @@ ECMA376Standard::ECMA376Standard(const EncryptionHeader &encryption_header,
5050ECMA376Standard::ECMA376Standard (const std::string &encryption_info) {
5151 const char *offset = encryption_info.data () + sizeof (VersionInfo);
5252
53- StandardHeader standard_header;
53+ StandardHeader standard_header{} ;
5454 std::memcpy (&standard_header, offset, sizeof (standard_header));
5555 offset += sizeof (standard_header);
5656
5757 std::memcpy (&m_encryption_header, offset, sizeof (m_encryption_header));
58- std::u16string csp_name_u16 (
58+ const std::u16string csp_name_u16 (
5959 reinterpret_cast <const char16_t *>(offset + sizeof (m_encryption_header)));
6060 const std::string csp_name = util::string::u16string_to_string (csp_name_u16);
6161 offset += standard_header.encryption_header_size ;
@@ -88,15 +88,15 @@ ECMA376Standard::derive_key(const std::string &password) const noexcept {
8888 to_little_endian (i, ibytes);
8989 hash = internal::crypto::util::sha1 (ibytes + hash);
9090 }
91- to_little_endian (( std::uint32_t ) 0 , ibytes);
91+ to_little_endian (static_cast < std::uint32_t >( 0 ) , ibytes);
9292 hash = internal::crypto::util::sha1 (hash + ibytes);
9393 }
9494
9595 std::string result;
9696 {
9797 const std::uint32_t cb_required_key_length =
9898 m_encryption_header.key_size / 8 ;
99- const std::uint32_t cb_hash = 20 ;
99+ constexpr std::uint32_t cb_hash = 20 ;
100100
101101 std::string buf1 (64 , ' \x36 ' );
102102 buf1 = xor_bytes (hash, buf1.substr (0 , cb_hash)) + buf1.substr (cb_hash);
@@ -128,7 +128,7 @@ bool ECMA376Standard::verify(const std::string &key) const noexcept {
128128std::string ECMA376Standard::decrypt (const std::string &encrypted_package,
129129 const std::string &key) const noexcept {
130130 const std::uint64_t total_size =
131- *( reinterpret_cast <const std::uint64_t *>(encrypted_package.data () ));
131+ *reinterpret_cast <const std::uint64_t *>(encrypted_package.data ());
132132 std::string result =
133133 internal::crypto::util::decrypt_aes_ecb (key, encrypted_package.substr (8 ))
134134 .substr (0 , total_size);
@@ -139,22 +139,22 @@ std::string ECMA376Standard::decrypt(const std::string &encrypted_package,
139139Util::Util (const std::string &encryption_info) {
140140 {
141141 // big endian is not supported
142- const std::uint16_t num = 1 ;
143- if (*( reinterpret_cast <const std::uint8_t *>(&num) ) != 1 ) {
142+ constexpr std::uint16_t num = 1 ;
143+ if (*reinterpret_cast <const std::uint8_t *>(&num) != 1 ) {
144144 throw UnsupportedEndian ();
145145 }
146146 }
147147
148- VersionInfo version_info;
148+ VersionInfo version_info{} ;
149149 std::memcpy (&version_info, encryption_info.data (), sizeof (version_info));
150- if ((( version_info.major == 2 ) || ( version_info.major == 3 ) ||
151- ( version_info.major == 4 ) ) &&
152- ( version_info.minor == 2 ) ) {
150+ if ((version_info.major == 2 || version_info.major == 3 ||
151+ version_info.major == 4 ) &&
152+ version_info.minor == 2 ) {
153153 impl = std::make_unique<ECMA376Standard>(encryption_info);
154- } else if (( version_info.major == 4 ) && ( version_info.minor == 4 ) ) {
154+ } else if (version_info.major == 4 && version_info.minor == 4 ) {
155155 throw MsUnsupportedCryptoAlgorithm (); // agile
156- } else if ((( version_info.major == 3 ) || ( version_info.major == 4 ) ) &&
157- ( version_info.minor == 3 ) ) {
156+ } else if ((version_info.major == 3 || version_info.major == 4 ) &&
157+ version_info.minor == 3 ) {
158158 throw MsUnsupportedCryptoAlgorithm (); // extensible
159159 } else {
160160 throw MsUnsupportedCryptoAlgorithm (); // unknown
0 commit comments