SWE-350 TOTP Generator
Milestone 5
The DE-10 board has six 7-segment displays, this can be used to display and generate a time based one-time pin (TOTP).
Loading...
Searching...
No Matches
BitBuffer.cpp
Go to the documentation of this file.
1
/*
2
* QR Code generator library (C++)
3
*
4
* Copyright (c) Project Nayuki
5
* https://www.nayuki.io/page/qr-code-generator-library
6
*
7
* (MIT License)
8
* Permission is hereby granted, free of charge, to any person obtaining a copy of
9
* this software and associated documentation files (the "Software"), to deal in
10
* the Software without restriction, including without limitation the rights to
11
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12
* the Software, and to permit persons to whom the Software is furnished to do so,
13
* subject to the following conditions:
14
* - The above copyright notice and this permission notice shall be included in
15
* all copies or substantial portions of the Software.
16
* - The Software is provided "as is", without warranty of any kind, express or
17
* implied, including but not limited to the warranties of merchantability,
18
* fitness for a particular purpose and noninfringement. In no event shall the
19
* authors or copyright holders be liable for any claim, damages or other
20
* liability, whether in an action of contract, tort or otherwise, arising from,
21
* out of or in connection with the Software or the use or other dealings in the
22
* Software.
23
*/
24
25
#include <cstddef>
26
#include "
BitBuffer.hpp
"
27
28
29
qrcodegen::BitBuffer::BitBuffer
() :
30
data(),
31
bitLength(0) {}
32
33
34
int
qrcodegen::BitBuffer::getBitLength
()
const
{
35
return
bitLength;
36
}
37
38
39
std::vector<uint8_t>
qrcodegen::BitBuffer::getBytes
()
const
{
40
return
data;
41
}
42
43
44
void
qrcodegen::BitBuffer::appendBits
(uint32_t val,
int
len) {
45
if
(len < 0 || len > 32 || (len < 32 && (val >> len) != 0))
46
throw
"Value out of range"
;
47
size_t
newBitLen = bitLength + len;
48
while
(data.size() * 8 < newBitLen)
49
data.push_back(0);
50
for
(
int
i = len - 1; i >= 0; i--, bitLength++)
// Append bit by bit
51
data.at(bitLength >> 3) |= ((val >> i) & 1) << (7 - (bitLength & 7));
52
}
53
54
55
void
qrcodegen::BitBuffer::appendData
(
const
QrSegment
&seg) {
56
size_t
newBitLen = bitLength + seg.
bitLength
;
57
while
(data.size() * 8 < newBitLen)
58
data.push_back(0);
59
for
(
int
i = 0; i < seg.
bitLength
; i++, bitLength++) {
// Append bit by bit
60
int
bit = (seg.
data
.at(i >> 3) >> (7 - (i & 7))) & 1;
61
data.at(bitLength >> 3) |= bit << (7 - (bitLength & 7));
62
}
63
}
BitBuffer.hpp
qrcodegen::BitBuffer::getBytes
std::vector< uint8_t > getBytes() const
Definition
BitBuffer.cpp:39
qrcodegen::BitBuffer::appendData
void appendData(const QrSegment &seg)
Definition
BitBuffer.cpp:55
qrcodegen::BitBuffer::BitBuffer
BitBuffer()
Definition
BitBuffer.cpp:29
qrcodegen::BitBuffer::getBitLength
int getBitLength() const
Definition
BitBuffer.cpp:34
qrcodegen::BitBuffer::appendBits
void appendBits(uint32_t val, int len)
Definition
BitBuffer.cpp:44
qrcodegen::QrSegment
Definition
QrSegment.hpp:41
qrcodegen::QrSegment::bitLength
const int bitLength
Definition
QrSegment.hpp:146
qrcodegen::QrSegment::data
const std::vector< uint8_t > data
Definition
QrSegment.hpp:143
QRCode
tests
BitBuffer.cpp
Generated by
1.12.0