int main(void) { unsigned char array[ARR_SIZE]; unsigned int i, prev; plan_tests(405); prev = 0; /* Test encode_length */ for (i = 1; i < 0x8000000; i *= 2) { ok1(encode_length(i-1) >= prev); ok1(encode_length(i) >= encode_length(i-1)); ok1(encode_length(i+1) >= encode_length(i)); prev = encode_length(i); } /* Test it against actual encoding return val. */ for (i = 1; i < 0x8000000; i *= 2) { ok1(encode_length(i-1) == encode(i - 1 + MIN_BLOCK_SIZE, false, array)); ok1(encode_length(i) == encode(i + MIN_BLOCK_SIZE, false, array)); ok1(encode_length(i+1) == encode(i + 1 + MIN_BLOCK_SIZE, false, array)); } /* Test encoder vs. decoder. */ for (i = 1; i < 0x8000000; i *= 2) { unsigned long hdrlen, len; bool free; hdrlen = encode(i - 1 + MIN_BLOCK_SIZE, false, array); ok1(decode(&len, &free, array) == hdrlen); ok1(len == i - 1 + MIN_BLOCK_SIZE); ok1(free == false); hdrlen = encode(i + MIN_BLOCK_SIZE, true, array); ok1(decode(&len, &free, array) == hdrlen); ok1(len == i + MIN_BLOCK_SIZE); ok1(free == true); hdrlen = encode(i + 1 + MIN_BLOCK_SIZE, true, array); ok1(decode(&len, &free, array) == hdrlen); ok1(len == i + 1 + MIN_BLOCK_SIZE); ok1(free == true); } return exit_status(); }
inline bool encode_geometry(mapnik::geometry::linear_ring<std::int64_t> const& ring, vector_tile::Tile_Feature & current_feature, int32_t & start_x, int32_t & start_y) { std::size_t ring_size = ring.size(); if (ring_size < 3) { return false; } unsigned line_to_length = static_cast<unsigned>(ring_size) - 1; unsigned count = 0; enum { move_to = 1, line_to = 2, coords = 3 } status = move_to; bool drop_last = false; if (ring.size() > 2 && ring.front() == ring.back()) { drop_last = true; line_to_length -= 1; if (line_to_length < 2) { return false; } } for (auto const& pt : ring) { if (status == move_to) { status = line_to; current_feature.add_geometry(9); // 1 | (move_to << 3) } else if (status == line_to) { status = coords; current_feature.add_geometry(encode_length(line_to_length)); } else if (drop_last && count == line_to_length + 1) { continue; } int32_t dx = pt.x - start_x; int32_t dy = pt.y - start_y; // Manual zigzag encoding. current_feature.add_geometry(protozero::encode_zigzag32(dx)); current_feature.add_geometry(protozero::encode_zigzag32(dy)); start_x = pt.x; start_y = pt.y; ++count; } current_feature.add_geometry(15); // close_path return true; }
secure_vector<byte> CCM_Mode::format_b0(size_t sz) { secure_vector<byte> B0(BS); const byte b_flags = (m_ad_buf.size() ? 64 : 0) + (((tag_size()/2)-1) << 3) + (L()-1); B0[0] = b_flags; copy_mem(&B0[1], m_nonce.data(), m_nonce.size()); encode_length(sz, &B0[m_nonce.size()+1]); return B0; }
secure_vector<uint8_t> CCM_Mode::format_b0(size_t sz) { secure_vector<uint8_t> B0(CCM_BS); const uint8_t b_flags = static_cast<uint8_t>((m_ad_buf.size() ? 64 : 0) + (((tag_size()/2)-1) << 3) + (L()-1)); B0[0] = b_flags; copy_mem(&B0[1], m_nonce.data(), m_nonce.size()); encode_length(sz, &B0[m_nonce.size()+1]); return B0; }
inline bool encode_geometry(mapnik::geometry::line_string<std::int64_t> const& line, vector_tile::Tile_Feature & current_feature, int32_t & start_x, int32_t & start_y) { std::size_t line_size = line.size(); if (line_size <= 0) { return false; } unsigned line_to_length = static_cast<unsigned>(line_size) - 1; enum { move_to = 1, line_to = 2, coords = 3 } status = move_to; for (auto const& pt : line) { if (status == move_to) { status = line_to; current_feature.add_geometry(9); // 1 | (move_to << 3) } else if (status == line_to) { status = coords; current_feature.add_geometry(encode_length(line_to_length)); } int32_t dx = pt.x - start_x; int32_t dy = pt.y - start_y; // Manual zigzag encoding. current_feature.add_geometry(protozero::encode_zigzag32(dx)); current_feature.add_geometry(protozero::encode_zigzag32(dy)); start_x = pt.x; start_y = pt.y; } return true; }
/* * Write the encoding of the byte(s) */ DER_Encoder& DER_Encoder::add_object(ASN1_Tag type_tag, ASN1_Tag class_tag, const uint8_t rep[], size_t length) { std::vector<uint8_t> hdr; encode_tag(hdr, type_tag, class_tag); encode_length(hdr, length); if(m_subsequences.size()) { m_subsequences[m_subsequences.size()-1].add_bytes(hdr.data(), hdr.size(), rep, length); } else if(m_append_output) { m_append_output(hdr.data(), hdr.size()); m_append_output(rep, length); } else { m_default_outbuf += hdr; m_default_outbuf += std::make_pair(rep, length); } return (*this); }