/* * Read a PEM or BER X.509 object */ void X509_Object::init(DataSource& in, const std::string& labels) { m_PEM_labels_allowed = split_on(labels, '/'); if(m_PEM_labels_allowed.size() < 1) throw Invalid_Argument("Bad labels argument to X509_Object"); m_PEM_label_pref = m_PEM_labels_allowed[0]; std::sort(m_PEM_labels_allowed.begin(), m_PEM_labels_allowed.end()); try { if(ASN1::maybe_BER(in) && !PEM_Code::matches(in)) { BER_Decoder dec(in); decode_from(dec); } else { std::string got_label; DataSource_Memory ber(PEM_Code::decode(in, got_label)); if(!std::binary_search(m_PEM_labels_allowed.begin(), m_PEM_labels_allowed.end(), got_label)) throw Decoding_Error("Invalid PEM label: " + got_label); BER_Decoder dec(ber); decode_from(dec); } } catch(Decoding_Error& e) { throw Decoding_Error(m_PEM_label_pref + " decoding failed: " + e.what()); } }
static void tcbdb_output (ErlDrvData handle, char* buf, int buflen) { TcDriverData* d = (TcDriverData*) handle; FromEmulator from = decode_from (d, buf, buflen); switch (from.type) { case EMULATOR_REQUEST_INVALID: reply_string (d->port, driver_caller (d->port), "invalid request"); break; default: driver_async (d->port, &d->magic, async_invoke, from_emulator_dup (&from), async_free); break; } }
/* * Read a PEM or BER X.509 object */ void X509_Object::load_data(DataSource& in) { try { if(ASN1::maybe_BER(in) && !PEM_Code::matches(in)) { BER_Decoder dec(in); decode_from(dec); } else { std::string got_label; DataSource_Memory ber(PEM_Code::decode(in, got_label)); if(got_label != PEM_label()) { bool is_alternate = false; for(std::string alt_label : alternate_PEM_labels()) { if(got_label == alt_label) { is_alternate = true; break; } } if(!is_alternate) throw Decoding_Error("Unexpected PEM label for " + PEM_label() + " of " + got_label); } BER_Decoder dec(ber); decode_from(dec); } } catch(Decoding_Error& e) { throw Decoding_Error(PEM_label() + " decoding", e); } }