Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dCache
cta
Commits
bc1bbfd0
Commit
bc1bbfd0
authored
5 years ago
by
Michael Davis
Browse files
Options
Downloads
Patches
Plain Diff
[checksum] Pads bytestrings with leading zeros to required length
parent
476056b9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/checksum/ChecksumBlob.cpp
+3
-2
3 additions, 2 deletions
common/checksum/ChecksumBlob.cpp
common/checksum/ChecksumBlobTest.cpp
+10
-10
10 additions, 10 deletions
common/checksum/ChecksumBlobTest.cpp
with
13 additions
and
12 deletions
common/checksum/ChecksumBlob.cpp
+
3
−
2
View file @
bc1bbfd0
...
...
@@ -35,11 +35,12 @@ void ChecksumBlob::insert(ChecksumType type, const std::string &value) {
case
MD5
:
expectedLength
=
16
;
break
;
case
SHA1
:
expectedLength
=
20
;
break
;
}
if
(
value
.
length
()
!=
expectedLength
)
throw
exception
::
ChecksumValueMismatch
(
if
(
value
.
length
()
>
expectedLength
)
throw
exception
::
ChecksumValueMismatch
(
"Checksum length type="
+
ChecksumTypeName
.
at
(
type
)
+
" expected="
+
std
::
to_string
(
expectedLength
)
+
" actual="
+
std
::
to_string
(
value
.
length
()));
m_cs
[
type
]
=
value
;
// Pad bytearray to expected length with trailing zeros
m_cs
[
type
]
=
value
+
std
::
string
(
expectedLength
-
value
.
length
(),
0
);
}
void
ChecksumBlob
::
insert
(
ChecksumType
type
,
uint32_t
value
)
{
...
...
This diff is collapsed.
Click to expand it.
common/checksum/ChecksumBlobTest.cpp
+
10
−
10
View file @
bc1bbfd0
...
...
@@ -62,14 +62,14 @@ TEST_F(cta_ChecksumBlobTest, checksum_types) {
ASSERT_EQ
(
checksumBlob
.
contains
(
SHA1
,
"12345678901234567890"
),
true
);
// invalid insertions
ASSERT_THROW
(
checksumBlob
.
insert
(
NONE
,
"0"
),
ChecksumValueMismatch
);
ASSERT_THROW
(
checksumBlob
.
insert
(
ADLER32
,
"12345"
),
ChecksumValueMismatch
);
ASSERT_THROW
(
checksumBlob
.
insert
(
CRC32
,
"123"
),
ChecksumValueMismatch
);
ASSERT_THROW
(
checksumBlob
.
insert
(
CRC32C
,
""
),
ChecksumValueMismatch
);
ASSERT_THROW
(
checksumBlob
.
insert
(
MD5
,
"1234
"
),
ChecksumValueMismatch
);
ASSERT_THROW
(
checksumBlob
.
insert
(
SHA1
,
"1234567890123456"
),
ChecksumValueMismatch
);
ASSERT_THROW
(
checksumBlob
.
insert
(
MD5
,
0x12345678
),
ChecksumTypeMismatch
);
ASSERT_THROW
(
checksumBlob
.
insert
(
SHA1
,
0x12345678
),
ChecksumTypeMismatch
);
ASSERT_THROW
(
checksumBlob
.
insert
(
NONE
,
"0"
),
ChecksumValueMismatch
);
ASSERT_THROW
(
checksumBlob
.
insert
(
ADLER32
,
"12345"
),
ChecksumValueMismatch
);
ASSERT_THROW
(
checksumBlob
.
insert
(
CRC32
,
"123
45
"
),
ChecksumValueMismatch
);
ASSERT_THROW
(
checksumBlob
.
insert
(
CRC32C
,
"
12345
"
),
ChecksumValueMismatch
);
ASSERT_THROW
(
checksumBlob
.
insert
(
MD5
,
"1234
5678901234567"
),
ChecksumValueMismatch
);
ASSERT_THROW
(
checksumBlob
.
insert
(
SHA1
,
"1234567890123456
78901
"
),
ChecksumValueMismatch
);
ASSERT_THROW
(
checksumBlob
.
insert
(
MD5
,
0x12345678
),
ChecksumTypeMismatch
);
ASSERT_THROW
(
checksumBlob
.
insert
(
SHA1
,
0x12345678
),
ChecksumTypeMismatch
);
// Blob types are different
ChecksumBlob
checksumBlob2
,
checksumBlob3
;
...
...
@@ -154,9 +154,9 @@ TEST_F(cta_ChecksumBlobTest, serialize_deserialize) {
ChecksumBlob
checksumBlob1
;
checksumBlob1
.
insert
(
NONE
,
""
);
// 0 bits
checksumBlob1
.
insert
(
ADLER32
,
"1234"
);
// 32 bits
checksumBlob1
.
insert
(
ADLER32
,
0
);
// 32 bits
checksumBlob1
.
insert
(
CRC32
,
"1234"
);
// 32 bits
checksumBlob1
.
insert
(
CRC32C
,
"
1234
"
);
// 32 bits
checksumBlob1
.
insert
(
CRC32C
,
"
FFFF
"
);
// 32 bits
checksumBlob1
.
insert
(
MD5
,
"1234567890123456"
);
// 128 bits
checksumBlob1
.
insert
(
SHA1
,
"12345678901234567890"
);
// 160 bits
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment