Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
DigestAlgorithm.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Cryptography_OpenSSL_DigestAlgorithm_h_
5#define _Stroika_Foundation_Cryptography_OpenSSL_DigestAlgorithm_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#if qStroika_HasComponent_OpenSSL
10#include <openssl/evp.h>
11#endif
12
13#include "Stroika/Foundation/Common/Common.h"
14#include "Stroika/Foundation/Common/Property.h"
15#include "Stroika/Foundation/Execution/Exceptions.h"
16#include "Stroika/Foundation/Execution/LazyInitialized.h"
17#include "Stroika/Foundation/Memory/Common.h"
18
19/**
20 * \file
21 *
22 * TODO:
23 * @todo document/enforce thread safety checks
24 */
25
26namespace Stroika::Foundation::Cryptography::Providers::OpenSSL {
27
28 using Characters::String;
29
30#if qStroika_HasComponent_OpenSSL
31
32 /**
33 * \brief object oriented wrapper on OpenSSL digest algorithms (const EVP_MD*)
34 */
35 class DigestAlgorithm {
36 public:
37 /**
38 */
39 DigestAlgorithm (const ::EVP_MD* digester);
40 DigestAlgorithm (const DigestAlgorithm& src);
41
42 public:
43 nonvirtual DigestAlgorithm& operator= (const DigestAlgorithm& src);
44
45 public:
46 /**
47 * Wrapper on DigestAlgorithm
48 *
49 * @see https://linux.die.net/man/3/evp_get_digestbyname
50 */
51 static DigestAlgorithm GetByName (const String& digestName);
52 static optional<DigestAlgorithm> GetByNameQuietly (const String& digestName);
53
54 public:
55 nonvirtual operator const ::EVP_MD* () const;
56
57 public:
58 /**
59 */
60 Common::ReadOnlyProperty<String> name;
61
62 public:
63 nonvirtual auto operator<=> (const DigestAlgorithm& rhs) const;
64 nonvirtual bool operator== (const DigestAlgorithm& rhs) const;
65
66 public:
67 /**
68 */
69 nonvirtual String ToString () const;
70
71 private:
72 const ::EVP_MD* fDigester_;
73 };
74
75 /**
76 * @see https://wiki.openssl.org/index.php/OpenSSL_3.0 section 9.3.3
77 */
78 namespace DigestAlgorithms {
79 /**
80 * very widely used, but not secure
81 */
82 extern const Execution::LazyInitialized<DigestAlgorithm> kMD5;
83
84 /**
85 * very widely used, but not secure
86 */
87 extern const Execution::LazyInitialized<DigestAlgorithm> kSHA1;
88
89 /**
90 * kSHA224, kSHA256, kSHA384, and kSHA512 are generally a good (secure) choice
91 */
92 extern const Execution::LazyInitialized<DigestAlgorithm> kSHA1_224;
93 extern const Execution::LazyInitialized<DigestAlgorithm> kSHA1_256;
94 extern const Execution::LazyInitialized<DigestAlgorithm> kSHA1_384;
95 extern const Execution::LazyInitialized<DigestAlgorithm> kSHA1_512;
96
97 /**
98 * https://www.veracode.com/blog/research/message-digests-aka-hashing-functions
99 */
100 extern const Execution::LazyInitialized<DigestAlgorithm> kSHA3_224;
101 extern const Execution::LazyInitialized<DigestAlgorithm> kSHA3_256;
102 extern const Execution::LazyInitialized<DigestAlgorithm> kSHA3_384;
103 extern const Execution::LazyInitialized<DigestAlgorithm> kSHA3_512;
104 }
105
106#endif
107
108}
109
110/*
111 ********************************************************************************
112 ***************************** Implementation Details ***************************
113 ********************************************************************************
114 */
115#include "DigestAlgorithm.inl"
116
117#endif /*_Stroika_Foundation_Cryptography_OpenSSL_DigestAlgorithm_h_*/
STRING_TYPE ToString(FLOAT_TYPE f, const ToStringOptions &options={})