void
Option6Auth::pack(isc::util::OutputBuffer& buf) const {
- if (buf.getCapacity() < (OPTION6_AUTH_MIN_LEN + OPTION6_HASH_MSG_LEN)) {
- isc_throw(OutOfRange, "Option " << type_ << "No space for"
- "computing packing data");
+ if (buf.getCapacity() < (OPTION6_AUTH_MIN_LEN + OPTION6_HASH_MSG_LEN + OPTION6_HDR)) {
+ isc_throw(OutOfRange, "Option " << type_ << "Buffer too small for"
+ "packing data");
}
//header = option code + length
void
Option6Auth::packHashInput(isc::util::OutputBuffer& buf) const {
- if (buf.getCapacity() < (OPTION6_AUTH_MIN_LEN + OPTION6_HASH_MSG_LEN)) {
- isc_throw(OutOfRange, "Option " << type_ << "No space for"
+ if (buf.getCapacity() < (OPTION6_AUTH_MIN_LEN + OPTION6_HASH_MSG_LEN + OPTION6_HDR)) {
+ isc_throw(OutOfRange, "Option " << type_ << "Buffer too small for"
"computing hash input");
}
output << in << "protocol= " << protocol_ << "algorithm= " << algorithm_
<< "rdm method= " << rdm_method_ << "rdm value= " << rdm_value_ ;
- return std::string(output);
+ return output.str();
}
} // end namespace dhcp
std::vector<uint8_t> test_buf(16,0xa8);
auth.reset(new Option6Auth(1,2,0,0x0090000000000000,test_buf));
- isc::util::OutputBuffer buf(29);//2 header + fixed 11 and key 16
+ isc::util::OutputBuffer buf(31);//4 header + fixed 11 and key 16
ASSERT_NO_THROW(auth->pack(buf));
const uint8_t ref_data[] = {
std::vector<uint8_t> test_buf(16,0xa8);
std::vector<uint8_t> hash_op(16,0x00);
- auth.reset(new Option6Auth(1,2,0,0x0090000000000000,test_buf));
+ auth.reset(new Option6Auth(1,2,0,0x0102030405060708,test_buf));
- isc::util::OutputBuffer buf(29);
- auth->packHashInput(buf);
- //auth info must be 0 for calculating the checksum
+ isc::util::OutputBuffer buf(31);
+ ASSERT_NO_THROW(auth->packHashInput(buf));
+ //auth info must be 0 for calculating the checksum
const uint8_t ref_data[] = {
0, 11, 0, 27, 1, 2, 0, //header , proto algo method
- 0, 0x90, 0, 0, 0, 0, 0, 0, //64 bit rdm field
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, //64 bit rdm field
0x00, 0x00, 0x00, 0x00, //128 bits/16 byte key
0x00, 0x00, 0x00, 0x00, //128 bits/16 byte key
0x00, 0x00, 0x00, 0x00, //128 bits/16 byte key
ASSERT_EQ(0, memcmp(ref_data, buf.getData(), buf.getLength()));
}
+TEST_F(Option6AuthTest, negativeCase) {
+ scoped_ptr<Option6Auth> auth;
+
+ std::vector<uint8_t> test_buf(16,0xa8);
+ auth.reset(new Option6Auth(1,2,0,0x0102030405060708,test_buf));
+ //allocate less space to force an exception to be thrown
+ isc::util::OutputBuffer buf(20);
+
+ ASSERT_THROW(auth->pack(buf), isc::OutOfRange);
+ ASSERT_THROW(auth->packHashInput(buf), isc::OutOfRange);
+
+}
+
} //end namespace