key.append(certProperties.signHash ? EVP_MD_name(certProperties.signHash) : "-");
if (certProperties.mimicCert) {
- BIO *bio = BIO_new_SBuf(&key);
- ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509), bio, (ASN1_VALUE *)certProperties.mimicCert.get());
+ Ssl::BIO_Pointer bio(BIO_new_SBuf(&key));
+ ASN1_item_i2d_bio(ASN1_ITEM_rptr(X509), bio.get(), (ASN1_VALUE *)certProperties.mimicCert.get());
}
}
bio_sbuf_write(BIO* bio, const char* data, int len)
{
SBuf *buf = static_cast<SBuf *>(BIO_get_data(bio));
+ // TODO: Convert exceptions into BIO errors
buf->append(data, len);
return len;
}
int
bio_sbuf_puts(BIO* bio, const char* data)
{
+ // TODO: use bio_sbuf_write() instead
SBuf *buf = static_cast<SBuf *>(BIO_get_data(bio));
size_t oldLen = buf->length();
buf->append(data);
SBuf *buf = static_cast<SBuf *>(BIO_get_data(bio));
switch (cmd) {
case BIO_CTRL_RESET:
+ // TODO: Convert exceptions into BIO errors
buf->clear();
return 1;
case BIO_CTRL_FLUSH:
}
}
-
-#if HAVE_LIBCRYPTO_BIO_METH_NEW
-static BIO_METHOD *BioSBufMethods = nullptr;
-#else
-static BIO_METHOD BioSBufMethods = {
- BIO_TYPE_MEM,
- "Squid SBuf",
- bio_sbuf_write,
- nullptr,
- bio_sbuf_puts,
- nullptr,
- bio_sbuf_ctrl,
- bio_sbuf_create,
- bio_sbuf_destroy,
- NULL,
-
-};
-#endif
-
BIO *Ssl::BIO_new_SBuf(SBuf *buf)
{
#if HAVE_LIBCRYPTO_BIO_METH_NEW
+ static BIO_METHOD *BioSBufMethods = nullptr;
if (!BioSBufMethods) {
BioSBufMethods = BIO_meth_new(BIO_TYPE_MEM, "Squid-SBuf");
BIO_meth_set_write(BioSBufMethods, bio_sbuf_write);
BIO_meth_set_destroy(BioSBufMethods, bio_sbuf_destroy);
}
#else
- BIO *bio = BIO_new(&BioSBufMethods);
+ static BIO_METHOD *BioSBufMethods = new BIO_METHOD({
+ BIO_TYPE_MEM,
+ "Squid SBuf",
+ bio_sbuf_write,
+ nullptr,
+ bio_sbuf_puts,
+ nullptr,
+ bio_sbuf_ctrl,
+ bio_sbuf_create,
+ bio_sbuf_destroy,
+ NULL
+ });
#endif
- if (!bio)
- return nullptr;
+ BIO *bio = BIO_new(BioSBufMethods);
+ Must(bio);
BIO_set_data(bio, buf);
BIO_set_init(bio, 1);
return bio;