|
QtPass 2.0.0
Developer documentation
|
RFC 4648 base32 codec, used for TOTP shared secrets. More...
#include <base32.h>
Static Public Member Functions | |
| static auto | decode (const QByteArray &encodedData) -> QByteArray |
| Decode strict RFC 4648 base32 data. | |
| static auto | encode (const QByteArray &data) -> QByteArray |
| Encode raw bytes as padded RFC 4648 base32. | |
| static auto | addPadding (const QByteArray &encodedData) -> QByteArray |
| Append '=' padding up to a multiple of 8 characters. | |
| static auto | removePadding (const QByteArray &encodedData) -> QByteArray |
| Strip trailing '=' padding. | |
| static auto | sanitizeInput (const QByteArray &encodedData) -> QByteArray |
| Make human-entered base32 text decodable. | |
Private Member Functions | |
| Base32 ()=default | |
| Static-only class; never instantiated. | |
RFC 4648 base32 codec, used for TOTP shared secrets.
Ported from KeePassXC (src/core/Base32.cpp). decode() is deliberately strict: the input length must be a multiple of 8 and every character must be in the base32 alphabet, so whitespace is an error rather than something to skip. Secrets that come from a human (or from a QR code label) therefore go through sanitizeInput() first, making the canonical entry point:
Failure is reported as an empty QByteArray. A successful decode of a non-empty input always yields at least one byte, so isEmpty() is an unambiguous error test.
|
staticnodiscard |
Append '=' padding up to a multiple of 8 characters.
| encodedData | Unpadded or partially padded base32 text. |
encodedData unchanged when its length remainder is impossible for base32 (1, 3 or 6). Definition at line 275 of file base32.cpp.
|
staticnodiscard |
Decode strict RFC 4648 base32 data.
| encodedData | Padded base32 text whose length is a multiple of 8. |
Definition at line 128 of file base32.cpp.
|
staticnodiscard |
Encode raw bytes as padded RFC 4648 base32.
| data | Raw bytes to encode. |
data is empty. Definition at line 191 of file base32.cpp.
|
staticnodiscard |
Strip trailing '=' padding.
| encodedData | Padded base32 text. |
encodedData unchanged when its length is not a multiple of 8. Definition at line 294 of file base32.cpp.
|
staticnodiscard |
Make human-entered base32 text decodable.
Drops every character outside "A-Za-z2-7" (so the spaces and dashes used to group a printed secret are tolerated), maps the digits that are ambiguous in the base32 alphabet (0 to O, 1 to L, 8 to B), then pads the result with addPadding().
| encodedData | Raw user input. |
Definition at line 305 of file base32.cpp.