| 34 | namespace mmkv { |
| 35 | |
| 36 | NSString *CodedInputDataCrypt::readNSString(KeyValueHolderCrypt &kvHolder) { |
| 37 | kvHolder.offset = static_cast<uint32_t>(m_position); |
| 38 | |
| 39 | int32_t size = this->readRawVarint32(true); |
| 40 | if (size < 0) { |
| 41 | throw length_error("InvalidProtocolBuffer negativeSize"); |
| 42 | } |
| 43 | |
| 44 | auto s_size = static_cast<size_t>(size); |
| 45 | if (s_size <= m_size - m_position) { |
| 46 | consumeBytes(s_size); |
| 47 | |
| 48 | kvHolder.keySize = static_cast<uint16_t>(s_size); |
| 49 | |
| 50 | auto ptr = m_decryptBuffer + m_decryptBufferPosition; |
| 51 | NSString *result = [[NSString alloc] initWithBytes:ptr length:s_size encoding:NSUTF8StringEncoding]; |
| 52 | m_position += s_size; |
| 53 | m_decryptBufferPosition += s_size; |
| 54 | return [result autorelease]; |
| 55 | } else { |
| 56 | throw out_of_range("InvalidProtocolBuffer truncatedMessage"); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | } // namespace mmkv |
| 61 |
nothing calls this directly
no test coverage detected