MCPcopy Create free account
hub / github.com/Icinga/icinga2 / Decode

Method Decode

lib/base/base64.cpp:30–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28}
29
30String Base64::Decode(const String& input)
31{
32 BIO *biomem = BIO_new_mem_buf(
33 const_cast<char*>(input.CStr()), input.GetLength());
34 BIO *bio64 = BIO_new(BIO_f_base64());
35 BIO_push(bio64, biomem);
36 BIO_set_flags(bio64, BIO_FLAGS_BASE64_NO_NL);
37
38 auto *outbuf = new char[input.GetLength()];
39
40 size_t len = 0;
41 int rc;
42
43 while ((rc = BIO_read(bio64, outbuf + len, input.GetLength() - len)) > 0)
44 len += rc;
45
46 String ret = String(outbuf, outbuf + len);
47 BIO_free_all(bio64);
48 delete [] outbuf;
49
50 if (ret.IsEmpty() && !input.IsEmpty())
51 throw std::invalid_argument("Not a valid base64 string");
52
53 return ret;
54}

Callers

nothing calls this directly

Calls 4

CStrMethod · 0.80
StringClass · 0.70
GetLengthMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected