std::vector<unsigned char> bdoc::X509Cert::encodeDER() const { int bufSize = i2d_X509(cert, NULL); if (bufSize < 0) { THROW_STACK_EXCEPTION("Failed to encode X509 cert to DER."); } std::vector<unsigned char> derEncodedX509(bufSize, 0); unsigned char* pBuf = &derEncodedX509[0]; bufSize = i2d_X509(cert, &pBuf); if (bufSize < 0) { THROW_STACK_EXCEPTION("Failed to encode X509 cert to DER."); } return derEncodedX509; }
/** * Encodes the X509 certificate using DER encoding. * * @return returns X509 certificate encoded in DER encoding. * @throws IOException throws exception if encoding failed. */ std::vector<unsigned char> digidoc::X509Cert::encodeDER() const throw(IOException) { // Get size of the DER encodes certificate. int bufSize = i2d_X509(cert, NULL); if(bufSize < 0) { THROW_IOEXCEPTION("Failed to encode X509 cert to DER."); } // Allocate memory for the DER encoding. std::vector<unsigned char> derEncodedX509(bufSize, 0); // DER encode X.509 certificate. unsigned char* pBuf = &derEncodedX509[0]; bufSize = i2d_X509(cert, &pBuf); if(bufSize < 0) { THROW_IOEXCEPTION("Failed to encode X509 cert to DER."); } return derEncodedX509; }