/* * 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"); } }
/* * 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()); } }
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); }
/* * 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); }
/* * 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); }
/* * 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); }
void X509_Time::decode_from(BER_Decoder& source) { BER_Object ber_time = source.get_next_object(); set_to(ASN1::to_string(ber_time), ber_time.type()); }