libxcks  0.1.0.1
xcksver.cpp
Go to the documentation of this file.
1 /*
2  * libxcks
3  * Copyright (C) 2022 Julien Couot
4  *
5  * This program is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13  * License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
24 //---------------------------------------------------------------------------
25 #include <cassert>
26 
27 #include "libxcks/xcksver.hpp"
28 #include "libxcks/ckfactory.hpp"
29 //---------------------------------------------------------------------------
30 
32 using namespace std;
33 //---------------------------------------------------------------------------
34 
35 
36 namespace libxcks
37 {
38 /*
39  * Gets the available names of algorithm for a version of (Z)XCKS file.
40  */
42 {
43  if (version == Version::V1_0_0)
44  return { "CRC-32", "CRC-64", "MD2", "MD4", "MD5", "RIPEMD-160",
45  "SHA-1", "SHA-224", "SHA-256", "SHA-384", "SHA-512",
46  "SHA3-224", "SHA3-256", "SHA3-384", "SHA3-512",
47  "BLAKE3", "SM3", "Tiger", "Whirlpool" };
48  else
49  return StringSet();
50 }
51 //---------------------------------------------------------------------------
52 
53 
54 /*
55  * Gets the available names of algorithm for a version of (Z)XCKS file.
56  */
57 LIBXCKS_SO_EXPORT const ArrayString getAvailableAlgorithmNamesAsArray(const Version version)
58 {
59  StringSet sumsAlgos = getAvailableAlgorithmNames(version);
60  ArrayString aSumsAlgos(sumsAlgos.cbegin(), sumsAlgos.cend());
61  return aSumsAlgos;
62 }
63 //---------------------------------------------------------------------------
64 
65 
66 /*
67  * Gets the available ids of algorithm for a version of (Z)XCKS file.
68  */
70 {
71  StringSet sumsAlgos = getAvailableAlgorithmNames(version);
73  for (const string& algoName : sumsAlgos)
74  {
75  ChecksumAlgoId id;
76  if (ChecksumFactory::getAlgorithmId(id, algoName, true))
77  ids.push_back(id);
78  }
79 
80  assert(ids.size() == sumsAlgos.size());
81 
82  return ids;
83 }
84 //---------------------------------------------------------------------------
85 
86 
87 /*
88  * Gets the name of an (Z)XCKS file version.
89  */
90 const string getXCKSVersionName(const Version version)
91 {
92  switch (version)
93  {
94  case Version::V1_0_0 :
95  return "1.0.0";
96 
97  default:
98  return "";
99  }
100 }
101 //---------------------------------------------------------------------------
102 
103 } // namespace libxcks
104 //---------------------------------------------------------------------------
Classes for enumerate and create all the checksums' algorithms that the application knows.
std::vector< ChecksumAlgoId > ArrayChecksumAlgoId
Array of ids of algorithms of checksums.
Definition: types.hpp:92
ChecksumAlgoId
Ids of algorithms of checksums.
Definition: types.hpp:65
std::vector< std::string > ArrayString
Array of strings.
Definition: types.hpp:44
Version
Known versions of XCKS file.
Definition: types.hpp:55
std::set< std::string > StringSet
Set of strings.
Definition: types.hpp:39
Versions of (Z)XCKS files.
LIBXCKS_SO_EXPORT const StringSet getAvailableAlgorithmNames(const Version version)
Gets the available names of algorithm for a version of (Z)XCKS file.
Definition: xcksver.cpp:41
LIBXCKS_SO_EXPORT const ArrayChecksumAlgoId getAvailableAlgorithmIds(const Version version)
Gets the available ids of algorithm for a version of (Z)XCKS file.
Definition: xcksver.cpp:69
LIBXCKS_SO_EXPORT const ArrayString getAvailableAlgorithmNamesAsArray(const Version version)
Gets the available names of algorithm for a version of (Z)XCKS file.
Definition: xcksver.cpp:57
LIBXCKS_SO_EXPORT const std::string getXCKSVersionName(const Version version)
Gets the name of an (Z)XCKS file version.
Definition: xcksver.cpp:90