MiKTeX 23.10-next
A scalable TeX distribution
Loading...
Searching...
No Matches
MD5.h
1/* miktex/Core/MD5.h: -*- C++ -*-
2
3 Copyright (C) 1996-2021 Christian Schenk
4
5 This file is part of the MiKTeX Core Library.
6
7 The MiKTeX Core Library is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2, or
10 (at your option) any later version.
11
12 The MiKTeX Core Library is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with the MiKTeX Core Library; if not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
21
22#pragma once
23
24#if !defined(F16928B95BB64B778B3E396992FFFCDD)
25#define F16928B95BB64B778B3E396992FFFCDD
26
27#include <miktex/Core/config.h>
28
29#include <algorithm>
30#include <array>
31#include <ostream>
32#include <string>
33#include <vector>
34
35#include <miktex/Util/PathName>
36
37#include "Utils.h"
38
39#include <md5.h>
40
41MIKTEX_CORE_BEGIN_NAMESPACE;
42
44class MD5 :
45 public std::array<md5_byte_t, 16>
46{
50public:
51 static MIKTEXCORECEEAPI(MD5) FromFile(const MiKTeX::Util::PathName& path);
52
56public:
57 static MIKTEXCORECEEAPI(MD5) FromChars(const std::string& s);
58
62public:
63 static MIKTEXCORECEEAPI(MD5) Parse(const std::string& hexString);
64
67public:
68 std::string ToString() const
69 {
70 return Utils::Hexify(&this->front(), this->size());
71 }
72};
73
76{
78public:
80 {
81 Init();
82 }
83
84public:
85 MD5Builder(const MD5Builder& other) = default;
86
87public:
88 MD5Builder& operator=(const MD5Builder& other) = default;
89
90public:
91 MD5Builder(MD5Builder&& other) = default;
92
93public:
94 MD5Builder& operator=(MD5Builder&& other) = default;
95
96public:
97 ~MD5Builder() = default;
98
100public:
101 void Init()
102 {
103 md5_init(&ctx);
104 }
105
109public:
110 void Update(const void* ptr, size_t size)
111 {
112 md5_append(&ctx, reinterpret_cast<const md5_byte_t*>(ptr), static_cast<int>(size));
113 }
114
117public:
119 {
120 md5_finish(&ctx, &md5[0]);
121 return md5;
122 }
123
126public:
127 MD5 GetMD5() const
128 {
129 return md5;
130 }
131
132private:
133 md5_state_t ctx;
134
135private:
136 MD5 md5;
137};
138
139inline std::ostream& operator<<(std::ostream& os, const MD5& md5)
140{
141 return os << md5.ToString();
142}
143
144
145MIKTEX_CORE_END_NAMESPACE;
146
147#endif
Instances of this struct can be used to calculate MD5 values.
Definition: MD5.h:76
MD5 Final()
Definition: MD5.h:118
MD5 GetMD5() const
Definition: MD5.h:127
void Update(const void *ptr, size_t size)
Definition: MD5.h:110
void Init()
Resets the state of this MD5Builder object.
Definition: MD5.h:101
MD5Builder()
Initializes a new MD5Builder object.
Definition: MD5.h:79
Instances of this struct represent MD5 values.
Definition: MD5.h:46
static MD5 FromChars(const std::string &s)
static MD5 FromFile(const MiKTeX::Util::PathName &path)
std::string ToString() const
Definition: MD5.h:68
static MD5 Parse(const std::string &hexString)
Instances of this class can be used to store path names.
Definition: PathName.h:73