Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sebastian Schrader
Kea
Commits
4c8efe3a
Commit
4c8efe3a
authored
Apr 25, 2013
by
Paul Selkirk
Browse files
[2521] Handle space-separated base-64 digest in DHCID, per Jinmei's review.
Also added more DHCID base-64 unittest cases.
parent
3bfd98d4
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/lib/dns/rdata/in_1/dhcid_49.cc
View file @
4c8efe3a
...
...
@@ -33,8 +33,15 @@ using namespace isc::util::encode;
void
DHCID
::
createFromLexer
(
MasterLexer
&
lexer
)
{
const
string
digest_txt
=
lexer
.
getNextToken
(
MasterToken
::
STRING
).
getString
();
string
digest_txt
=
lexer
.
getNextToken
(
MasterToken
::
STRING
).
getString
();
while
(
true
)
{
const
MasterToken
&
token
=
lexer
.
getNextToken
();
if
(
token
.
getType
()
!=
MasterToken
::
STRING
)
{
break
;
}
digest_txt
.
append
(
token
.
getString
());
}
lexer
.
ungetToken
();
decodeBase64
(
digest_txt
,
digest_
);
// RFC4701 states DNS software should consider the RDATA section to
...
...
@@ -67,13 +74,12 @@ DHCID::DHCID(const std::string& dhcid_str) {
std
::
istringstream
iss
(
dhcid_str
);
MasterLexer
lexer
;
lexer
.
pushSource
(
iss
);
createFromLexer
(
lexer
);
if
(
lexer
.
getNextToken
().
getType
()
!=
MasterToken
::
END_OF_FILE
)
{
isc_throw
(
InvalidRdataText
,
"extra input text for DHCID: "
<<
dhcid_str
);
}
createFromLexer
(
lexer
);
// RFC4701 says we have to support white-space-separated substrings,
// so we have to read to the end of input. Therefore, we can't detect
// extra input past the end of the digest. OTOH, extra text is likely
// to result in a base64 decoding error, so BadValue will be thrown in
// that case.
}
catch
(
const
MasterLexer
::
LexerError
&
ex
)
{
isc_throw
(
InvalidRdataText
,
"Failed to construct DHCID from '"
<<
dhcid_str
<<
"': "
<<
ex
.
what
());
...
...
src/lib/dns/tests/rdata_dhcid_unittest.cc
View file @
4c8efe3a
// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
// Copyright (C) 2011
-2013
Internet Systems Consortium, Inc. ("ISC")
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
...
...
@@ -43,6 +43,24 @@ TEST_F(Rdata_DHCID_Test, createFromString) {
EXPECT_EQ
(
0
,
rdata_dhcid2
.
compare
(
rdata_dhcid
));
}
TEST_F
(
Rdata_DHCID_Test
,
spaceSeparatedBase64
)
{
const
in
::
DHCID
rdata_dhcid2
(
"0LIg0LvQtdGB0YMg 0YDQvtC00LjQu9Cw 0YHRjCDRkdC70L7R h9C60LA="
);
EXPECT_EQ
(
0
,
rdata_dhcid2
.
compare
(
rdata_dhcid
));
}
TEST_F
(
Rdata_DHCID_Test
,
multiLineBase64
)
{
const
in
::
DHCID
rdata_dhcid2
(
"( 0LIg0LvQtdGB0YMg0YDQvtC00LjQu9Cw
\n
0YHRjCDRkdC70L7R h9C60LA= )"
);
EXPECT_EQ
(
0
,
rdata_dhcid2
.
compare
(
rdata_dhcid
));
}
TEST_F
(
Rdata_DHCID_Test
,
extraText
)
{
EXPECT_THROW
(
const
in
::
DHCID
rdata_dhcid2
(
"0LIg0LvQtdGB0YMg 0YDQvtC00LjQu9Cw 0YHRjCDRkdC70L7R h9C60LA="
" superextrabogustext"
),
isc
::
BadValue
);
}
TEST_F
(
Rdata_DHCID_Test
,
badBase64
)
{
EXPECT_THROW
(
const
in
::
DHCID
rdata_dhcid_bad
(
"00"
),
isc
::
BadValue
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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