1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "crypto/openssl_bio_string.h"
7 #include <openssl/bio.h>
14 int bio_string_write(BIO
* bio
, const char* data
, int len
) {
15 reinterpret_cast<std::string
*>(bio
->ptr
)->append(data
, len
);
19 int bio_string_puts(BIO
* bio
, const char* data
) {
20 // Note: unlike puts(), BIO_puts does not add a newline.
21 return bio_string_write(bio
, data
, strlen(data
));
24 long bio_string_ctrl(BIO
* bio
, int cmd
, long num
, void* ptr
) {
25 std::string
* str
= reinterpret_cast<std::string
*>(bio
->ptr
);
41 int bio_string_new(BIO
* bio
) {
47 int bio_string_free(BIO
* bio
) {
48 // The string is owned by the caller, so there's nothing to do here.
52 BIO_METHOD bio_string_methods
= {
53 // TODO(mattm): Should add some type number too? (bio.h uses 1-24)
63 NULL
, /* callback_ctrl */
68 BIO
* BIO_new_string(std::string
* out
) {
69 BIO
* bio
= BIO_new(&bio_string_methods
);