Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Cryptography/Format.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
6#include <cstdio>
7
9
10#include "Format.h"
11
12using namespace Stroika::Foundation;
13
14string Cryptography::Private_::mkArrayFmt_ (const uint8_t* start, const uint8_t* end)
15{
16 string result;
17 size_t N = end - start;
18 result.reserve (2 * N + 1); // think need to leave space for NUL-terminator?
19 for (const uint8_t* i = start; i != end; ++i) {
20 char b[10];
21 b[0] = '\0';
22 ::snprintf (b, Memory::NEltsOf (b), "%02x", *i);
23 result += b;
24 }
25 return result;
26}
27
28string Cryptography::Private_::mkFmt_ (unsigned int n)
29{
30 char b[1024];
31 b[0] = '\0';
32 ::snprintf (b, Memory::NEltsOf (b), "0x%u", n);
33 return b;
34}
35
36string Cryptography::Private_::mkFmt_ (unsigned long n)
37{
38 char b[1024];
39 b[0] = '\0';
40 ::snprintf (b, Memory::NEltsOf (b), "0x%lu", n);
41 return b;
42}
43
44string Cryptography::Private_::mkFmt_ (unsigned long long n)
45{
46 char b[1024];
47 b[0] = '\0';
48 ::snprintf (b, Memory::NEltsOf (b), "0x%llu", n);
49 return b;
50}