本文整理汇总了C++中BER_Decoder类的典型用法代码示例。如果您正苦于以下问题:C++ BER_Decoder类的具体用法?C++ BER_Decoder怎么用?C++ BER_Decoder使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BER_Decoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: decoder
/*
* Decode BER encoded parameters
*/
void DL_Group::BER_decode(const std::vector<byte>& data,
Format format)
{
BigInt new_p, new_q, new_g;
BER_Decoder decoder(data);
BER_Decoder ber = decoder.start_cons(SEQUENCE);
if(format == ANSI_X9_57)
{
ber.decode(new_p)
.decode(new_q)
.decode(new_g)
.verify_end();
}
else if(format == ANSI_X9_42)
{
ber.decode(new_p)
.decode(new_g)
.decode(new_q)
.discard_remaining();
}
else if(format == PKCS_3)
{
ber.decode(new_p)
.decode(new_g)
.discard_remaining();
}
else
throw Invalid_Argument("Unknown DL_Group encoding " + std::to_string(format));
initialize(new_p, new_q, new_g);
}
示例2: sequence
/*
* Decode a BER encoded DistinguishedName
*/
void X509_DN::decode_from(BER_Decoder& source)
{
MemoryVector<byte> bits;
source.start_cons(SEQUENCE)
.raw_bytes(bits)
.end_cons();
BER_Decoder sequence(bits);
while(sequence.more_items())
{
BER_Decoder rdn = sequence.start_cons(SET);
while(rdn.more_items())
{
OID oid;
ASN1_String str;
rdn.start_cons(SEQUENCE)
.decode(oid)
.decode(str)
.verify_end()
.end_cons();
add_attribute(oid, str.value());
}
}
dn_bits = bits;
}
示例3: m_response_bits
Response::Response(const uint8_t response_bits[], size_t response_bits_len) :
m_response_bits(response_bits, response_bits + response_bits_len)
{
m_dummy_response_status = Certificate_Status_Code::OCSP_RESPONSE_INVALID;
BER_Decoder response_outer = BER_Decoder(m_response_bits).start_cons(SEQUENCE);
size_t resp_status = 0;
response_outer.decode(resp_status, ENUMERATED, UNIVERSAL);
if(resp_status != 0)
throw Exception("OCSP response status " + std::to_string(resp_status));
if(response_outer.more_items())
{
BER_Decoder response_bytes =
response_outer.start_cons(ASN1_Tag(0), CONTEXT_SPECIFIC).start_cons(SEQUENCE);
response_bytes.decode_and_check(OID("1.3.6.1.5.5.7.48.1.1"),
"Unknown response type in OCSP response");
BER_Decoder basicresponse =
BER_Decoder(response_bytes.get_next_octet_string()).start_cons(SEQUENCE);
basicresponse.start_cons(SEQUENCE)
.raw_bytes(m_tbs_bits)
.end_cons()
.decode(m_sig_algo)
.decode(m_signature, BIT_STRING);
decode_optional_list(basicresponse, ASN1_Tag(0), m_certs);
size_t responsedata_version = 0;
Extensions extensions;
BER_Decoder(m_tbs_bits)
.decode_optional(responsedata_version, ASN1_Tag(0),
ASN1_Tag(CONSTRUCTED | CONTEXT_SPECIFIC))
.decode_optional(m_signer_name, ASN1_Tag(1),
ASN1_Tag(CONSTRUCTED | CONTEXT_SPECIFIC))
.decode_optional_string(m_key_hash, OCTET_STRING, 2,
ASN1_Tag(CONSTRUCTED | CONTEXT_SPECIFIC))
.decode(m_produced_at)
.decode_list(m_responses)
.decode_optional(extensions, ASN1_Tag(1),
ASN1_Tag(CONSTRUCTED | CONTEXT_SPECIFIC));
}
response_outer.end_cons();
}
示例4: 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());
}
}
示例5: decode_from
/*
* Decode a BER encoded AlgorithmIdentifier
*/
void AlgorithmIdentifier::decode_from(BER_Decoder& codec)
{
codec.start_cons(SEQUENCE)
.decode(oid)
.raw_bytes(parameters)
.end_cons();
}
示例6: decode_from
/*
* 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");
}
}
示例7: decompress
/*
* Decompress a message
*/
void CMS_Decoder::decompress(BER_Decoder& decoder)
{
size_t version;
AlgorithmIdentifier comp_algo;
BER_Decoder comp_info = decoder.start_cons(SEQUENCE);
comp_info.decode(version);
if(version != 0)
throw Decoding_Error("CMS: Unknown version for CompressedData");
comp_info.decode(comp_algo);
read_econtent(comp_info);
comp_info.end_cons();
Filter* decompressor = 0;
info = comp_algo.oid.as_string();
#if defined(BOTAN_HAS_COMPRESSOR_ZLIB)
if(comp_algo.oid == OIDS::lookup("Compression.Zlib"))
{
decompressor = new Zlib_Decompression;
info = "Zlib";
}
#endif
if(!decompressor)
status = FAILURE;
Pipe pipe(decompressor);
pipe.process_msg(data);
data = pipe.read_all();
}
示例8: decode_from
/*
* Decode a BER encoded Attribute
*/
void Attribute::decode_from(BER_Decoder& codec)
{
codec.start_cons(SEQUENCE)
.decode(oid)
.start_cons(SET)
.raw_bytes(parameters)
.end_cons()
.end_cons();
}
示例9:
void X509_Time::decode_from(BER_Decoder& source)
{
BER_Object ber_time = source.get_next_object();
set_to(Charset::transcode(ASN1::to_string(ber_time),
LATIN1_CHARSET,
LOCAL_CHARSET),
ber_time.type_tag);
}
示例10: decode_from
/*
* Decode a BER encoded CRL_Entry
*/
void CRL_Entry::decode_from(BER_Decoder& source)
{
BigInt serial_number_bn;
source.start_cons(SEQUENCE)
.decode(serial_number_bn)
.decode(time);
if(source.more_items())
{
Extensions extensions(throw_on_unknown_critical);
source.decode(extensions);
Data_Store info;
extensions.contents_to(info, info);
reason = CRL_Code(info.get1_u32bit("X509v3.CRLReasonCode"));
}
serial = BigInt::encode(serial_number_bn);
}
示例11: data
/*
* Decode a BER encoded CRL_Entry
*/
void CRL_Entry::decode_from(BER_Decoder& source)
{
BigInt serial_number_bn;
std::unique_ptr<CRL_Entry_Data> data(new CRL_Entry_Data);
BER_Decoder entry = source.start_cons(SEQUENCE);
entry.decode(serial_number_bn).decode(data->m_time);
data->m_serial = BigInt::encode(serial_number_bn);
if(entry.more_items())
{
entry.decode(data->m_extensions);
if(auto ext = data->m_extensions.get_extension_object_as<Cert_Extension::CRL_ReasonCode>())
{
data->m_reason = ext->get_reason();
}
else
{
data->m_reason = UNSPECIFIED;
}
}
entry.end_cons();
m_data.reset(data.release());
}
示例12: if
/*
* Decode a BER encoded ASN1_String
*/
void ASN1_String::decode_from(BER_Decoder& source)
{
BER_Object obj = source.get_next_object();
Character_Set charset_is;
if(obj.type_tag == BMP_STRING)
charset_is = UCS2_CHARSET;
else if(obj.type_tag == UTF8_STRING)
charset_is = UTF8_CHARSET;
else
charset_is = LATIN1_CHARSET;
*this = ASN1_String(
Charset::transcode(ASN1::to_string(obj), charset_is, LOCAL_CHARSET),
obj.type_tag);
}
示例13: message
/*
* 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::string message("decoding type mismatch for ASN1_EAC_String, tag is ");
std::stringstream ss;
std::string str_is;
ss << std::hex << obj.type_tag;
ss >> str_is;
message.append(str_is);
message.append(", while it should be ");
std::stringstream ss2;
std::string str_should;
ss2 << std::hex << this->tag;
ss2 >> str_should;
message.append(str_should);
throw Decoding_Error(message);
}
示例14: decode
/*
* Decode a BER encoded KeyUsage
*/
void decode(BER_Decoder& source, Key_Constraints& key_usage)
{
BER_Object obj = source.get_next_object();
if(obj.type_tag != BIT_STRING || obj.class_tag != UNIVERSAL)
throw BER_Bad_Tag("Bad tag for usage constraint",
obj.type_tag, obj.class_tag);
if(obj.value.size() != 2 && obj.value.size() != 3)
throw BER_Decoding_Error("Bad size for BITSTRING in usage constraint");
if(obj.value[0] >= 8)
throw BER_Decoding_Error("Invalid unused bits in usage constraint");
const byte mask = (0xFF << obj.value[0]);
obj.value[obj.value.size()-1] &= mask;
u16bit usage = 0;
for(u32bit j = 1; j != obj.value.size(); ++j)
usage = (obj.value[j] << 8) | usage;
key_usage = Key_Constraints(usage);
}
示例15: strlen
bool ne7ssh_keys::getDSAKeys (char* buffer, uint32 size)
{
// DataSource_Memory privKeyPEMSrc (privKeyPEMStr);
const char* headerDSA = "-----BEGIN DSA PRIVATE KEY-----\n";
const char* footerDSA = "-----END DSA PRIVATE KEY-----\n";
SecureVector<Botan::byte> keyDataRaw;
BigInt p, q, g, y, x;
char *start;
uint32 version;
start = buffer + strlen(headerDSA);
Pipe base64dec (new Base64_Decoder);
base64dec.process_msg ((Botan::byte*)start, size - strlen(footerDSA) - strlen(headerDSA));
keyDataRaw = base64dec.read_all (PIPE_DEFAULT_MESSAGE);
BER_Decoder decoder (keyDataRaw);
#if BOTAN_PRE_15
BER_Decoder sequence = BER::get_subsequence(decoder);
BER::decode (sequence, version);
#else
BER_Decoder sequence = decoder.start_cons (SEQUENCE);
sequence.decode (version);
#endif
if (version)
{
ne7ssh::errors()->push (-1, "Encountered unknown DSA key version.");
return false;
}
#if BOTAN_PRE_15
BER::decode (sequence, p);
BER::decode (sequence, q);
BER::decode (sequence, g);
BER::decode (sequence, y);
BER::decode (sequence, x);
#else
sequence.decode (p);
sequence.decode (q);
sequence.decode (g);
sequence.decode (y);
sequence.decode (x);
#endif
sequence.discard_remaining();
sequence.verify_end();
if (p.is_zero() || q.is_zero() || g.is_zero() || y.is_zero() || x.is_zero())
{
ne7ssh::errors()->push (-1, "Could not decode the supplied DSA key.");
return false;
}
DL_Group dsaGroup (p, q, g);
#if BOTAN_PRE_18 || BOTAN_PRE_15
dsaPrivateKey = new DSA_PrivateKey (dsaGroup, x);
#else
dsaPrivateKey = new DSA_PrivateKey (*ne7ssh::rng, dsaGroup, x);
#endif
publicKeyBlob.clear();
publicKeyBlob.addString ("ssh-dss");
publicKeyBlob.addBigInt (p);
publicKeyBlob.addBigInt (q);
publicKeyBlob.addBigInt (g);
publicKeyBlob.addBigInt (y);
return true;
}