-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCipherIterator.cpp
More file actions
97 lines (85 loc) · 2.59 KB
/
Copy pathCipherIterator.cpp
File metadata and controls
97 lines (85 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include <cstddef>
#include <algorithm>
#include "Cipher.h"
#include "CipherAlgorithm.h"
#ifdef MEMTRACE
#include "memtrace.h"
#endif
using const_iterator = Cipher::const_iterator;
const_iterator::const_iterator(const Cipher* parent_ptr, const char *pointed_char) :
parent_cipher(parent_ptr),
ciphered_ptr(pointed_char)
{ }
const_iterator::const_iterator(const const_iterator &source_iter) :
parent_cipher(source_iter.parent_cipher),
ciphered_ptr(source_iter.ciphered_ptr)
{ }
void swap(const_iterator &a, const_iterator &b) noexcept {
using std::swap;
swap(a.parent_cipher, b.parent_cipher);
swap(a.ciphered_ptr, b.ciphered_ptr);
}
const_iterator& const_iterator::operator=(const_iterator source_iter) {
swap(*this, source_iter);
return *this;
}
const_iterator::reference const_iterator::operator*() const {
using Mode = Algorithm::Mode;
return parent_cipher->cipher_algorithm->transform(Mode::decrypt, *ciphered_ptr);
}
const_iterator::reference const_iterator::operator[](int idx) const {
return *(*this + idx);
}
const_iterator& const_iterator::operator+=(size_t rhs) {
ciphered_ptr += rhs;
return *this;
}
const_iterator& const_iterator::operator-=(size_t rhs) {
ciphered_ptr -= rhs;
return *this;
}
const_iterator& const_iterator::operator++() {
++ciphered_ptr;
return *this;
}
const_iterator& const_iterator::operator--() {
--ciphered_ptr;
return *this;
}
const_iterator const_iterator::operator++(int) {
auto tmp = *this;
++ciphered_ptr;
return tmp;
}
const_iterator const_iterator::operator--(int) {
auto tmp = *this;
--ciphered_ptr;
return tmp;
}
const_iterator const_iterator::operator+(size_t rhs) const {
return const_iterator(parent_cipher, ciphered_ptr + rhs);
}
const_iterator const_iterator::operator-(size_t rhs) const {
return const_iterator(parent_cipher, ciphered_ptr - rhs);
}
bool const_iterator::operator==(const const_iterator &rhs_it) const {
return this->ciphered_ptr == rhs_it.ciphered_ptr;
}
bool const_iterator::operator!=(const const_iterator &rhs_it) const {
return !(*this == rhs_it);
}
bool const_iterator::operator<(const const_iterator &rhs_it) const {
return this->ciphered_ptr < rhs_it.ciphered_ptr;
}
bool const_iterator::operator>=(const const_iterator &rhs_it) const {
return !(*this < rhs_it);
}
bool const_iterator::operator>(const const_iterator &rhs_it) const {
return rhs_it < *this;
}
bool const_iterator::operator<=(const const_iterator &rhs_it) const {
return rhs_it >= *this;
}
const_iterator::difference_type const_iterator::operator-(const const_iterator &rhs) const {
return this->ciphered_ptr - rhs.ciphered_ptr;
}