Coverage Report

Created: 2023-02-13 06:21

/src/botan/build/include/botan/symkey.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
* OctetString
3
* (C) 1999-2007 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_SYMKEY_H_
9
#define BOTAN_SYMKEY_H_
10
11
#include <botan/secmem.h>
12
#include <string>
13
14
namespace Botan {
15
16
class RandomNumberGenerator;
17
18
/**
19
* Octet String
20
*/
21
class BOTAN_PUBLIC_API(2,0) OctetString final
22
   {
23
   public:
24
      /**
25
      * @return size of this octet string in bytes
26
      */
27
37.5k
      size_t length() const { return m_data.size(); }
28
2.14k
      size_t size() const { return m_data.size(); }
29
30
      /**
31
      * @return this object as a secure_vector<uint8_t>
32
      */
33
15.6k
      secure_vector<uint8_t> bits_of() const { return m_data; }
34
35
      /**
36
      * @return start of this string
37
      */
38
2.32k
      const uint8_t* begin() const { return m_data.data(); }
39
40
      /**
41
      * @return end of this string
42
      */
43
0
      const uint8_t* end() const   { return begin() + m_data.size(); }
44
45
      /**
46
      * @return this encoded as hex
47
      */
48
      std::string to_string() const;
49
50
      /**
51
      * XOR the contents of another octet string into this one
52
      * @param other octet string
53
      * @return reference to this
54
      */
55
      OctetString& operator^=(const OctetString& other);
56
57
      /**
58
      * Force to have odd parity
59
      *
60
      * Deprecated. There is no reason to use this outside of interacting with
61
      * some very old or weird system which requires DES and also which do not
62
      * automatically ignore the parity bits.
63
      */
64
      BOTAN_DEPRECATED("Why would you need to do this")
65
      void set_odd_parity();
66
67
      /**
68
      * Create a new OctetString
69
      * @param str is a hex encoded string
70
      */
71
      explicit OctetString(const std::string& str = "");
72
73
      /**
74
      * Create a new random OctetString
75
      * @param rng is a random number generator
76
      * @param len is the desired length in bytes
77
      */
78
      OctetString(RandomNumberGenerator& rng, size_t len);
79
80
      /**
81
      * Create a new OctetString
82
      * @param in is an array
83
      * @param len is the length of in in bytes
84
      */
85
      OctetString(const uint8_t in[], size_t len);
86
87
      /**
88
      * Create a new OctetString
89
      * @param in a bytestring
90
      */
91
7.56k
      OctetString(const secure_vector<uint8_t>& in) : m_data(in) {}
92
93
      /**
94
      * Create a new OctetString
95
      * @param in a bytestring
96
      */
97
0
      OctetString(const std::vector<uint8_t>& in) : m_data(in.begin(), in.end()) {}
98
99
   private:
100
      secure_vector<uint8_t> m_data;
101
   };
102
103
/**
104
* Compare two strings
105
* @param x an octet string
106
* @param y an octet string
107
* @return if x is equal to y
108
*/
109
BOTAN_PUBLIC_API(2,0) bool operator==(const OctetString& x,
110
                          const OctetString& y);
111
112
/**
113
* Compare two strings
114
* @param x an octet string
115
* @param y an octet string
116
* @return if x is not equal to y
117
*/
118
BOTAN_PUBLIC_API(2,0) bool operator!=(const OctetString& x,
119
                          const OctetString& y);
120
121
/**
122
* Concatenate two strings
123
* @param x an octet string
124
* @param y an octet string
125
* @return x concatenated with y
126
*/
127
BOTAN_PUBLIC_API(2,0) OctetString operator+(const OctetString& x,
128
                                const OctetString& y);
129
130
/**
131
* XOR two strings
132
* @param x an octet string
133
* @param y an octet string
134
* @return x XORed with y
135
*/
136
BOTAN_PUBLIC_API(2,0) OctetString operator^(const OctetString& x,
137
                                const OctetString& y);
138
139
140
/**
141
* Alternate name for octet string showing intent to use as a key
142
*/
143
using SymmetricKey = OctetString;
144
145
/**
146
* Alternate name for octet string showing intent to use as an IV
147
*/
148
using InitializationVector = OctetString;
149
150
}
151
152
#endif