Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
fb92bdb5
Commit
fb92bdb5
authored
Dec 19, 2010
by
mattijs
Browse files
ENH: SHA1Digest : Istream construction
parent
3f60b19d
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.C
View file @
fb92bdb5
...
...
@@ -32,7 +32,37 @@ License
//! @cond fileScope
const
char
hexChars
[]
=
"0123456789abcdef"
;
//! @endcond
//! @endcond fileScope
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
unsigned
char
Foam
::
SHA1Digest
::
readHexDigit
(
Istream
&
is
)
{
// Takes into account that 'a' (or 'A') is 10
static
const
label
alphaOffset
=
toupper
(
'A'
)
-
10
;
// Takes into account that '0' is 0
static
const
label
zeroOffset
=
int
(
'0'
);
char
c
=
0
;
is
.
read
(
c
);
if
(
!
isxdigit
(
c
))
{
FatalIOErrorIn
(
"SHA1Digest::readHexDigit(Istream&)"
,
is
)
<<
"Illegal hex digit: '"
<<
c
<<
"'"
<<
exit
(
FatalIOError
);
}
if
(
isdigit
(
c
))
{
return
int
(
c
)
-
zeroOffset
;
}
else
{
return
toupper
(
c
)
-
alphaOffset
;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
...
...
@@ -43,6 +73,12 @@ Foam::SHA1Digest::SHA1Digest()
}
Foam
::
SHA1Digest
::
SHA1Digest
(
Istream
&
is
)
{
is
>>
*
this
;
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
void
Foam
::
SHA1Digest
::
clear
()
...
...
@@ -75,6 +111,23 @@ bool Foam::SHA1Digest::operator!=(const SHA1Digest& rhs) const
// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
Foam
::
Istream
&
Foam
::
operator
>>
(
Istream
&
is
,
SHA1Digest
&
dig
)
{
unsigned
char
*
v
=
dig
.
v_
;
for
(
unsigned
i
=
0
;
i
<
dig
.
length
;
++
i
)
{
unsigned
char
c1
=
SHA1Digest
::
readHexDigit
(
is
);
unsigned
char
c2
=
SHA1Digest
::
readHexDigit
(
is
);
v
[
i
]
=
(
c1
<<
4
)
+
c2
;
}
is
.
check
(
"Istream& operator>>(Istream&, SHA1Digest&)"
);
return
is
;
}
Foam
::
Ostream
&
Foam
::
operator
<<
(
Ostream
&
os
,
const
SHA1Digest
&
dig
)
{
const
unsigned
char
*
v
=
dig
.
v_
;
...
...
src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H
View file @
fb92bdb5
...
...
@@ -45,11 +45,13 @@ namespace Foam
// Forward declaration of classes
class
Ostream
;
class
Istream
;
// Forward declaration of friend functions and operators
class
SHA1
;
class
SHA1Digest
;
Ostream
&
operator
<<
(
Ostream
&
,
const
SHA1Digest
&
);
Istream
&
operator
>>
(
Istream
&
,
SHA1Digest
&
);
/*---------------------------------------------------------------------------*\
...
...
@@ -67,6 +69,9 @@ public:
//- Construct a zero digest
SHA1Digest
();
//- Construct read a digest
SHA1Digest
(
Istream
&
);
//- Reset the digest to zero
void
clear
();
...
...
@@ -77,11 +82,14 @@ public:
bool
operator
!=
(
const
SHA1Digest
&
)
const
;
friend
Ostream
&
operator
<<
(
Ostream
&
,
const
SHA1Digest
&
);
friend
Istream
&
operator
>>
(
Istream
&
,
SHA1Digest
&
);
private:
//- The digest contents
unsigned
char
v_
[
length
];
static
unsigned
char
readHexDigit
(
Istream
&
);
};
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment