| 125 | } |
| 126 | |
| 127 | void CodedInputDataCrypt::skipBytes(size_t length) { |
| 128 | m_position += length; |
| 129 | |
| 130 | auto decryptedBytesLeft = m_decryptBufferDecryptLength - m_decryptBufferPosition; |
| 131 | if (decryptedBytesLeft >= length) { |
| 132 | m_decryptBufferPosition += length; |
| 133 | return; |
| 134 | } |
| 135 | length -= decryptedBytesLeft; |
| 136 | // if this happens, we need optimization like the alignDecrypter above |
| 137 | assert(m_decrypter.m_number == 0); |
| 138 | |
| 139 | size_t alignSize = ((length + AES_IV_LEN - 1) / AES_IV_LEN) * AES_IV_LEN; |
| 140 | auto bytesLeftInSrc = m_size - m_decryptPosition; |
| 141 | auto size = min(alignSize, bytesLeftInSrc); |
| 142 | decryptedBytesLeft = size - length; |
| 143 | for (size_t index = 0, round = size / AES_IV_LEN; index < round; index++) { |
| 144 | m_decrypter.decrypt(m_ptr + m_decryptPosition, m_decryptBuffer, AES_IV_LEN); |
| 145 | m_decryptPosition += AES_IV_LEN; |
| 146 | size -= AES_IV_LEN; |
| 147 | } |
| 148 | if (size) { |
| 149 | m_decrypter.decrypt(m_ptr + m_decryptPosition, m_decryptBuffer, size); |
| 150 | m_decryptPosition += size; |
| 151 | m_decryptBufferPosition = size - decryptedBytesLeft; |
| 152 | m_decryptBufferDecryptLength = size; |
| 153 | } else { |
| 154 | m_decryptBufferPosition = AES_IV_LEN - decryptedBytesLeft; |
| 155 | m_decryptBufferDecryptLength = AES_IV_LEN; |
| 156 | } |
| 157 | assert(m_decryptBufferPosition <= m_decryptBufferDecryptLength); |
| 158 | assert(m_decryptPosition - m_decryptBufferDecryptLength + m_decryptBufferPosition == m_position); |
| 159 | } |
| 160 | |
| 161 | inline void CodedInputDataCrypt::statusBeforeDecrypt(size_t rollbackSize, AESCryptStatus &status) { |
| 162 | rollbackSize += m_decryptBufferDecryptLength - m_decryptBufferPosition; |