Base64.h
Go to the documentation of this file.
1 /****
2  * Base64.h
3  *
4  * Copyright 2020 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the Sming UPnP Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  ****/
19 
20 #pragma once
21 
22 #include <Data/WebHelpers/base64.h>
23 #include <cstring>
24 
25 namespace UPnP
26 {
27 class Base64
28 {
29 public:
31  {
32  }
33 
34  Base64(const String& data) : data(data)
35  {
36  }
37 
38  operator String() const
39  {
40  return data;
41  }
42 
43  Base64& operator=(const char* value)
44  {
45  if(value == nullptr) {
46  data = nullptr;
47  } else {
48  data = base64_decode(value, strlen(value));
49  }
50  return *this;
51  }
52 
53  explicit operator bool() const
54  {
55  return bool(data);
56  }
57 
58  String encode() const
59  {
60  return base64_encode(data);
61  }
62 
63 private:
64  String data;
65 };
66 
67 } // namespace UPnP
int base64_encode(size_t in_len, const unsigned char *in, size_t out_len, char *out)
encode binary data into base64 digits with MIME style === pads
int base64_decode(size_t in_len, const char *in, size_t out_len, unsigned char *out)
decode base64 digits with MIME style === pads into binary data
The String class.
Definition: WString.h:137
Definition: Base64.h:28
Base64(const String &data)
Definition: Base64.h:34
Base64()
Definition: Base64.h:30
String encode() const
Definition: Base64.h:58
Base64 & operator=(const char *value)
Definition: Base64.h:43
Definition: ActionRequest.h:25