SessionId.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * SessionId.h
8  *
9  ****/
10 
11 #pragma once
12 
13 #include "WString.h"
14 #include <Data/HexString.h>
15 
16 namespace Ssl
17 {
21 class SessionId
22 {
23 public:
24  const uint8_t* getValue() const
25  {
26  return reinterpret_cast<const uint8_t*>(value.c_str());
27  }
28 
29  unsigned getLength() const
30  {
31  return value.length();
32  }
33 
34  bool isValid() const
35  {
36  return getLength() != 0;
37  }
38 
39  bool assign(const uint8_t* newValue, unsigned newLength)
40  {
41  if(!value.setLength(newLength)) {
42  return false;
43  }
44  memcpy(value.begin(), newValue, newLength);
45  return true;
46  }
47 
51  String toString() const
52  {
53  return makeHexString(getValue(), getLength());
54  }
55 
56 private:
57  String value;
58 };
59 
60 __forceinline String toString(const SessionId& id)
61 {
62  return id.toString();
63 }
64 
65 } // namespace Ssl
String makeHexString(const void *data, unsigned length, char separator='\0')
Convert data into a hexadecimal string representation.
Manages buffer to store SSL Session ID.
Definition: SessionId.h:22
String toString() const
Return a string representation of the session ID.
Definition: SessionId.h:51
bool assign(const uint8_t *newValue, unsigned newLength)
Definition: SessionId.h:39
bool isValid() const
Definition: SessionId.h:34
unsigned getLength() const
Definition: SessionId.h:29
const uint8_t * getValue() const
Definition: SessionId.h:24
The String class.
Definition: WString.h:137
const char * c_str() const
Get a constant (un-modifiable) pointer to String content.
Definition: WString.h:616
bool setLength(size_t length)
set the string length accordingly, expanding if necessary
char * begin()
Get a modifiable pointer to String content.
Definition: WString.h:625
size_t length(void) const
Obtain the String length in characters, excluding NUL terminator.
Definition: WString.h:243
Definition: Alert.h:16
String toString(Certificate::RDN rdn)
Obtain a string describing the given name component.