SSHFP::SSHFP(const std::string& sshfp_str) {
std::istringstream iss(sshfp_str);
- // peekc should be of iss's char_type for isspace to work
- std::istringstream::char_type peekc;
std::stringbuf fingerprintbuf;
uint32_t algorithm, fingerprint_type;
isc_throw(InvalidRdataText, "SSHFP fingerprint type out of range");
}
- iss.read(&peekc, 1);
- if (!iss.good() || !isspace(peekc, iss.getloc())) {
- isc_throw(InvalidRdataText, "SSHFP presentation format error");
- }
-
iss >> &fingerprintbuf;
-
- algorithm_ = algorithm;
- fingerprint_type_ = fingerprint_type;
-
try {
decodeHex(fingerprintbuf.str(), fingerprint_);
} catch (const isc::BadValue& e) {
- isc_throw(InvalidRdataText, "Bad SSHFP fingerprint: " << e.what());
+ isc_throw(InvalidRdataText,
+ "Bad SSHFP fingerprint: " << e.what());
}
+
+ algorithm_ = algorithm;
+ fingerprint_type_ = fingerprint_type;
}
SSHFP::SSHFP(uint8_t algorithm, uint8_t fingerprint_type,
SSHFP::toWire(OutputBuffer& buffer) const {
buffer.writeUint8(algorithm_);
buffer.writeUint8(fingerprint_type_);
- buffer.writeData(&fingerprint_[0], fingerprint_.size());
+
+ if (fingerprint_.size() > 0) {
+ buffer.writeData(&fingerprint_[0], fingerprint_.size());
+ }
}
void
SSHFP::toWire(AbstractMessageRenderer& renderer) const {
renderer.writeUint8(algorithm_);
renderer.writeUint8(fingerprint_type_);
- renderer.writeData(&fingerprint_[0], fingerprint_.size());
+
+ if (fingerprint_.size() > 0) {
+ renderer.writeData(&fingerprint_[0], fingerprint_.size());
+ }
}
string
return (fingerprint_type_);
}
+size_t
+SSHFP::getFingerprintLen() const {
+ return (fingerprint_.size());
+}
+
// END_RDATA_NAMESPACE
// END_ISC_NAMESPACE
const string sshfp_txt("2 1 123456789abcdef67890123456789abcdef67890");
const generic::SSHFP rdata_sshfp(2, 1, "123456789abcdef67890123456789abcdef67890");
+const uint8_t rdata_sshfp_wiredata[] = {
+ // algorithm
+ 0x02,
+ // fingerprint type
+ 0x01,
+ // fingerprint
+ 0x12, 0x34, 0x56, 0x78,
+ 0x9a, 0xbc, 0xde, 0xf6,
+ 0x78, 0x90, 0x12, 0x34,
+ 0x56, 0x78, 0x9a, 0xbc,
+ 0xde, 0xf6, 0x78, 0x90
+};
TEST_F(Rdata_SSHFP_Test, createFromText) {
// Basic test
TEST_F(Rdata_SSHFP_Test, badText) {
EXPECT_THROW(const generic::SSHFP rdata_sshfp("1"), InvalidRdataText);
- EXPECT_THROW(const generic::SSHFP rdata_sshfp("1 2"), InvalidRdataText);
EXPECT_THROW(const generic::SSHFP rdata_sshfp("BUCKLE MY SHOES"), InvalidRdataText);
EXPECT_THROW(const generic::SSHFP rdata_sshfp("1 2 foo bar"), InvalidRdataText);
}
EXPECT_TRUE(boost::iequals(sshfp_txt, rdata_sshfp.toText()));
}
+TEST_F(Rdata_SSHFP_Test, toWire) {
+ this->obuffer.clear();
+ rdata_sshfp.toWire(this->obuffer);
+
+ EXPECT_EQ(22, this->obuffer.getLength());
+
+ EXPECT_PRED_FORMAT4(UnitTestUtil::matchWireData,
+ this->obuffer.getData(),
+ this->obuffer.getLength(),
+ rdata_sshfp_wiredata, sizeof(rdata_sshfp_wiredata));
+}
+
TEST_F(Rdata_SSHFP_Test, getSSHFPAlgorithmNumber) {
EXPECT_EQ(2, rdata_sshfp.getSSHFPAlgorithmNumber());
}
TEST_F(Rdata_SSHFP_Test, getSSHFPFingerprintType) {
EXPECT_EQ(1, rdata_sshfp.getSSHFPFingerprintType());
}
+
+TEST_F(Rdata_SSHFP_Test, getFingerprintLen) {
+ EXPECT_EQ(20, rdata_sshfp.getFingerprintLen());
+}
+
+TEST_F(Rdata_SSHFP_Test, emptyFingerprintFromWire) {
+ const generic::SSHFP& rdf =
+ dynamic_cast<const generic::SSHFP&>
+ (*rdataFactoryFromFile(RRType("SSHFP"), RRClass("IN"),
+ "rdata_sshfp_fromWire12"));
+
+ EXPECT_EQ(4, rdf.getSSHFPAlgorithmNumber());
+ EXPECT_EQ(9, rdf.getSSHFPFingerprintType());
+ EXPECT_EQ(0, rdf.getFingerprintLen());
+}
+
+TEST_F(Rdata_SSHFP_Test, emptyFingerprintFromString) {
+ const generic::SSHFP rdata_sshfp2("5 6");
+
+ EXPECT_EQ(5, rdata_sshfp2.getSSHFPAlgorithmNumber());
+ EXPECT_EQ(6, rdata_sshfp2.getSSHFPFingerprintType());
+ EXPECT_EQ(0, rdata_sshfp2.getFingerprintLen());
+}
}