本文整理匯總了C++中Decoding_Error函數的典型用法代碼示例。如果您正苦於以下問題:C++ Decoding_Error函數的具體用法?C++ Decoding_Error怎麽用?C++ Decoding_Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Decoding_Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: Decoding_Error
/*
* Decode a BER encoded ASN1_EAC_String
*/
void ASN1_EAC_String::decode_from(BER_Decoder& source)
{
BER_Object obj = source.get_next_object();
if(obj.type_tag != this->tag)
{
std::stringstream ss;
ss << "ASN1_EAC_String tag mismatch, tag was "
<< std::hex << obj.type_tag
<< " expected "
<< std::hex << this->tag;
throw Decoding_Error(ss.str());
}
Character_Set charset_is;
charset_is = LATIN1_CHARSET;
try
{
*this = ASN1_EAC_String(
Charset::transcode(ASN1::to_string(obj), charset_is, LOCAL_CHARSET),
obj.type_tag);
}
catch(Invalid_Argument inv_arg)
{
throw Decoding_Error(std::string("ASN1_EAC_String decoding failed: ") +
inv_arg.what());
}
}
示例2: Decoding_Error
Application_Layer_Protocol_Notification::Application_Layer_Protocol_Notification(TLS_Data_Reader& reader,
u16bit extension_size)
{
if(extension_size == 0)
return; // empty extension
const u16bit name_bytes = reader.get_u16bit();
size_t bytes_remaining = extension_size - 2;
if(name_bytes != bytes_remaining)
throw Decoding_Error("Bad encoding of ALPN extension, bad length field");
while(bytes_remaining)
{
const std::string p = reader.get_string(1, 0, 255);
if(bytes_remaining < p.size() + 1)
throw Decoding_Error("Bad encoding of ALPN, length field too long");
bytes_remaining -= (p.size() + 1);
m_protocols.push_back(p);
}
}
示例3: BER_Decoding_Error
/*
* Decode a BER encoded EAC_Time
*/
void EAC_Time::decode_from(BER_Decoder& source)
{
BER_Object obj = source.get_next_object();
if(obj.type_tag != this->tag)
throw BER_Decoding_Error("Tag mismatch when decoding");
if(obj.value.size() != 6)
{
throw Decoding_Error("EAC_Time decoding failed");
}
try
{
u32bit tmp_year = dec_two_digit(obj.value[0], obj.value[1]);
u32bit tmp_mon = dec_two_digit(obj.value[2], obj.value[3]);
u32bit tmp_day = dec_two_digit(obj.value[4], obj.value[5]);
year = tmp_year + 2000;
month = tmp_mon;
day = tmp_day;
}
catch (Invalid_Argument)
{
throw Decoding_Error("EAC_Time decoding failed");
}
}
示例4: Decoding_Error
/**
* Deserialize a Certificate message
*/
Certificate::Certificate(const std::vector<byte>& buf)
{
if(buf.size() < 3)
throw Decoding_Error("Certificate: Message malformed");
const size_t total_size = make_u32bit(0, buf[0], buf[1], buf[2]);
if(total_size != buf.size() - 3)
throw Decoding_Error("Certificate: Message malformed");
const byte* certs = buf.data() + 3;
while(size_t remaining_bytes = buf.data() + buf.size() - certs)
{
if(remaining_bytes < 3)
throw Decoding_Error("Certificate: Message malformed");
const size_t cert_size = make_u32bit(0, certs[0], certs[1], certs[2]);
if(remaining_bytes < (3 + cert_size))
throw Decoding_Error("Certificate: Message malformed");
DataSource_Memory cert_buf(&certs[3], cert_size);
m_certs.push_back(X509_Certificate(cert_buf));
certs += cert_size + 3;
}
}
示例5: make_private_key
Private_Key* make_private_key(const AlgorithmIdentifier& alg_id,
const secure_vector<byte>& key_bits,
RandomNumberGenerator& rng)
{
const std::string alg_name = OIDS::lookup(alg_id.oid);
if(alg_name == "")
throw Decoding_Error("Unknown algorithm OID: " + alg_id.oid.as_string());
#if defined(BOTAN_HAS_RSA)
if(alg_name == "RSA")
return new RSA_PrivateKey(alg_id, key_bits, rng);
#endif
#if defined(BOTAN_HAS_RW)
if(alg_name == "RW")
return new RW_PrivateKey(alg_id, key_bits, rng);
#endif
#if defined(BOTAN_HAS_DSA)
if(alg_name == "DSA")
return new DSA_PrivateKey(alg_id, key_bits, rng);
#endif
#if defined(BOTAN_HAS_DIFFIE_HELLMAN)
if(alg_name == "DH")
return new DH_PrivateKey(alg_id, key_bits, rng);
#endif
#if defined(BOTAN_HAS_NYBERG_RUEPPEL)
if(alg_name == "NR")
return new NR_PrivateKey(alg_id, key_bits, rng);
#endif
#if defined(BOTAN_HAS_ELGAMAL)
if(alg_name == "ElGamal")
return new ElGamal_PrivateKey(alg_id, key_bits, rng);
#endif
#if defined(BOTAN_HAS_ECDSA)
if(alg_name == "ECDSA")
return new ECDSA_PrivateKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_GOST_34_10_2001)
if(alg_name == "GOST-34.10")
return new GOST_3410_PrivateKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_ECDH)
if(alg_name == "ECDH")
return new ECDH_PrivateKey(alg_id, key_bits);
#endif
#if defined(BOTAN_HAS_CURVE_25519)
if(alg_name == "Curve25519")
return new Curve25519_PrivateKey(alg_id, key_bits, rng);
#endif
throw Decoding_Error("Unhandled PK algorithm " + alg_name);
}
示例6: Decoding_Error
/*
* Unpad with ANSI X9.23 Method
*/
size_t ANSI_X923_Padding::unpad(const byte block[], size_t size) const
{
size_t position = block[size-1];
if(position > size)
throw Decoding_Error(name());
for(size_t j = size-position; j != size-1; ++j)
if(block[j] != 0)
throw Decoding_Error(name());
return (size-position);
}
示例7: Decoding_Error
void Datagram_Handshake_IO::Handshake_Reassembly::add_fragment(
const uint8_t fragment[],
size_t fragment_length,
size_t fragment_offset,
uint16_t epoch,
uint8_t msg_type,
size_t msg_length)
{
if(complete())
return; // already have entire message, ignore this
if(m_msg_type == HANDSHAKE_NONE)
{
m_epoch = epoch;
m_msg_type = msg_type;
m_msg_length = msg_length;
}
if(msg_type != m_msg_type || msg_length != m_msg_length || epoch != m_epoch)
throw Decoding_Error("Inconsistent values in fragmented DTLS handshake header");
if(fragment_offset > m_msg_length)
throw Decoding_Error("Fragment offset past end of message");
if(fragment_offset + fragment_length > m_msg_length)
throw Decoding_Error("Fragment overlaps past end of message");
if(fragment_offset == 0 && fragment_length == m_msg_length)
{
m_fragments.clear();
m_message.assign(fragment, fragment+fragment_length);
}
else
{
/*
* FIXME. This is a pretty lame way to do defragmentation, huge
* overhead with a tree node per byte.
*
* Also should confirm that all overlaps have no changes,
* otherwise we expose ourselves to the classic fingerprinting
* and IDS evasion attacks on IP fragmentation.
*/
for(size_t i = 0; i != fragment_length; ++i)
m_fragments[fragment_offset+i] = fragment[i];
if(m_fragments.size() == m_msg_length)
{
m_message.resize(m_msg_length);
for(size_t i = 0; i != m_msg_length; ++i)
m_message[i] = m_fragments[i];
m_fragments.clear();
}
}
}
示例8: while
/*
* Split up and process handshake messages
*/
void TLS_Server::read_handshake(byte rec_type,
const MemoryRegion<byte>& rec_buf)
{
if(rec_type == HANDSHAKE)
{
if(!state)
state = new Handshake_State;
state->queue.write(&rec_buf[0], rec_buf.size());
}
while(true)
{
Handshake_Type type = HANDSHAKE_NONE;
SecureVector<byte> contents;
if(rec_type == HANDSHAKE)
{
if(state->queue.size() >= 4)
{
byte head[4] = { 0 };
state->queue.peek(head, 4);
const size_t length = make_u32bit(0, head[1], head[2], head[3]);
if(state->queue.size() >= length + 4)
{
type = static_cast<Handshake_Type>(head[0]);
contents.resize(length);
state->queue.read(head, 4);
state->queue.read(&contents[0], contents.size());
}
}
}
else if(rec_type == CHANGE_CIPHER_SPEC)
{
if(state->queue.size() == 0 && rec_buf.size() == 1 && rec_buf[0] == 1)
type = HANDSHAKE_CCS;
else
throw Decoding_Error("Malformed ChangeCipherSpec message");
}
else
throw Decoding_Error("Unknown message type in handshake processing");
if(type == HANDSHAKE_NONE)
break;
process_handshake_msg(type, contents);
if(type == HANDSHAKE_CCS || !state)
break;
}
}
示例9: cert_req_info
/*
* Deocde the CertificateRequestInfo
*/
void PKCS10_Request::force_decode()
{
BER_Decoder cert_req_info(m_tbs_bits);
size_t version;
cert_req_info.decode(version);
if(version != 0)
throw Decoding_Error("Unknown version code in PKCS #10 request: " +
std::to_string(version));
X509_DN dn_subject;
cert_req_info.decode(dn_subject);
m_info.add(dn_subject.contents());
BER_Object public_key = cert_req_info.get_next_object();
if(public_key.type_tag != SEQUENCE || public_key.class_tag != CONSTRUCTED)
throw BER_Bad_Tag("PKCS10_Request: Unexpected tag for public key",
public_key.type_tag, public_key.class_tag);
m_info.add("X509.Certificate.public_key",
PEM_Code::encode(
ASN1::put_in_sequence(unlock(public_key.value)),
"PUBLIC KEY"
)
);
BER_Object attr_bits = cert_req_info.get_next_object();
if(attr_bits.type_tag == 0 &&
attr_bits.class_tag == ASN1_Tag(CONSTRUCTED | CONTEXT_SPECIFIC))
{
BER_Decoder attributes(attr_bits.value);
while(attributes.more_items())
{
Attribute attr;
attributes.decode(attr);
handle_attribute(attr);
}
attributes.verify_end();
}
else if(attr_bits.type_tag != NO_OBJECT)
throw BER_Bad_Tag("PKCS10_Request: Unexpected tag for attributes",
attr_bits.type_tag, attr_bits.class_tag);
cert_req_info.verify_end();
if(!this->check_signature(subject_public_key()))
throw Decoding_Error("PKCS #10 request: Bad signature detected");
}
示例10: while
/*
* Unpad with One and Zeros Method
*/
size_t OneAndZeros_Padding::unpad(const byte block[], size_t size) const
{
while(size)
{
if(block[size-1] == 0x80)
break;
if(block[size-1] != 0x00)
throw Decoding_Error(name());
size--;
}
if(!size)
throw Decoding_Error(name());
return (size-1);
}
示例11: Decoding_Error
/**
* Deserialize a Certificate Request message
*/
Certificate_Req::Certificate_Req(const std::vector<byte>& buf,
Protocol_Version version)
{
if(buf.size() < 4)
throw Decoding_Error("Certificate_Req: Bad certificate request");
TLS_Data_Reader reader("CertificateRequest", buf);
std::vector<byte> cert_type_codes = reader.get_range_vector<byte>(1, 1, 255);
for(size_t i = 0; i != cert_type_codes.size(); ++i)
{
const std::string cert_type_name = cert_type_code_to_name(cert_type_codes[i]);
if(cert_type_name.empty()) // something we don't know
continue;
m_cert_key_types.push_back(cert_type_name);
}
if(version.supports_negotiable_signature_algorithms())
{
std::vector<byte> sig_hash_algs = reader.get_range_vector<byte>(2, 2, 65534);
if(sig_hash_algs.size() % 2 != 0)
throw Decoding_Error("Bad length for signature IDs in certificate request");
for(size_t i = 0; i != sig_hash_algs.size(); i += 2)
{
std::string hash = Signature_Algorithms::hash_algo_name(sig_hash_algs[i]);
std::string sig = Signature_Algorithms::sig_algo_name(sig_hash_algs[i+1]);
m_supported_algos.push_back(std::make_pair(hash, sig));
}
}
const u16bit purported_size = reader.get_u16bit();
if(reader.remaining_bytes() != purported_size)
throw Decoding_Error("Inconsistent length in certificate request");
while(reader.has_remaining())
{
std::vector<byte> name_bits = reader.get_range_vector<byte>(2, 0, 65535);
BER_Decoder decoder(name_bits.data(), name_bits.size());
X509_DN name;
decoder.decode(name);
m_names.push_back(name);
}
}
示例12: while
/*
* Decompress Input with Gzip
*/
void Gzip_Decompression::write(const byte input_arr[], size_t length)
{
if(length) no_writes = false;
// non-const needed by gzip api :(
Bytef* input = reinterpret_cast<Bytef*>(const_cast<byte*>(input_arr));
gzip->stream.next_in = input;
gzip->stream.avail_in = length;
while(gzip->stream.avail_in != 0)
{
gzip->stream.next_out = reinterpret_cast<Bytef*>(&buffer[0]);
gzip->stream.avail_out = buffer.size();
int rc = inflate(&(gzip->stream), Z_SYNC_FLUSH);
if(rc != Z_OK && rc != Z_STREAM_END)
{
clear();
if(rc == Z_DATA_ERROR)
throw Decoding_Error("Gzip_Decompression: Data integrity error");
else if(rc == Z_NEED_DICT)
throw Decoding_Error("Gzip_Decompression: Need preset dictionary");
else if(rc == Z_MEM_ERROR)
throw Memory_Exhaustion();
else
throw std::runtime_error("Gzip decompression: Unknown error");
}
send(&buffer[0], buffer.size() - gzip->stream.avail_out);
if(rc == Z_STREAM_END)
{
size_t read_from_block = length - gzip->stream.avail_in;
clear();
gzip = new Gzip_Stream;
if(inflateInit2(&(gzip->stream), (raw_deflate ? -15 : (MAX_WBITS + 32))) != Z_OK) {
throw Memory_Exhaustion();
}
gzip->stream.next_in = input + read_from_block;
gzip->stream.avail_in = length - read_from_block;
input += read_from_block;
length -= read_from_block;
}
}
}
示例13: timespec_to_u32bit
/*************************************************
* Convert a string into a time duration *
*************************************************/
u32bit timespec_to_u32bit(const std::string& timespec)
{
if(timespec == "")
return 0;
const char suffix = timespec[timespec.size()-1];
std::string value = timespec.substr(0, timespec.size()-1);
u32bit scale = 1;
if(Charset::is_digit(suffix))
value += suffix;
else if(suffix == 's')
scale = 1;
else if(suffix == 'm')
scale = 60;
else if(suffix == 'h')
scale = 60 * 60;
else if(suffix == 'd')
scale = 24 * 60 * 60;
else if(suffix == 'y')
scale = 365 * 24 * 60 * 60;
else
throw Decoding_Error("timespec_to_u32bit: Bad input " + timespec);
return scale * to_u32bit(value);
}
示例14: Decoding_Error
Certificate_Status::Certificate_Status(const std::vector<uint8_t>& buf)
{
if(buf.size() < 5)
throw Decoding_Error("Invalid Certificate_Status message: too small");
if(buf[0] != 1) // not OCSP
throw Decoding_Error("Unexpected Certificate_Status message: unexpected response type");
size_t len = make_uint32(0, buf[1], buf[2], buf[3]);
// Verify the redundant length field...
if(buf.size() != len + 4)
throw Decoding_Error("Invalid Certificate_Status: invalid length field");
m_response.assign(buf.begin() + 4, buf.end());
}
示例15: EC_Group
EC_PrivateKey::EC_PrivateKey(const AlgorithmIdentifier& alg_id,
const secure_vector<byte>& key_bits)
{
m_domain_params = EC_Group(alg_id.parameters);
m_domain_encoding = EC_DOMPAR_ENC_EXPLICIT;
OID key_parameters;
secure_vector<byte> public_key_bits;
BER_Decoder(key_bits)
.start_cons(SEQUENCE)
.decode_and_check<size_t>(1, "Unknown version code for ECC key")
.decode_octet_string_bigint(m_private_key)
.decode_optional(key_parameters, ASN1_Tag(0), PRIVATE)
.decode_optional_string(public_key_bits, BIT_STRING, 1, PRIVATE)
.end_cons();
if(!key_parameters.empty() && key_parameters != alg_id.oid)
throw Decoding_Error("EC_PrivateKey - inner and outer OIDs did not match");
if(public_key_bits.empty())
{
m_public_key = domain().get_base_point() * m_private_key;
BOTAN_ASSERT(m_public_key.on_the_curve(),
"Public point derived from loaded key was on the curve");
}
else
{
m_public_key = OS2ECP(public_key_bits, domain().get_curve());
// OS2ECP verifies that the point is on the curve
}
}