Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-tidy fixes #478

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/tins/dns.h
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ class TINS_API DNS : public PDU {
* \param domain_name The domain name to encode.
* \return The encoded domain name.
*/
static std::string encode_domain_name(const std::string& domain_name);
static std::string encode_domain_name(const std::string& dn);

/**
* \brief Decodes a domain name
Expand Down
2 changes: 1 addition & 1 deletion include/tins/dot11/dot11_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ class TINS_API Dot11ManagementFrame : public Dot11 {
*
* \param elements The new list of elements.
*/
void request_information(const request_info_type elements);
void request_information(const request_info_type& elements);

/**
* \brief Helper method to set the FH parameter set tagged option.
Expand Down
30 changes: 15 additions & 15 deletions include/tins/eapol.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,25 +131,25 @@ class TINS_API EAPOL : public PDU {
* \brief Sets the version field.
* \param value The new version to be set.
*/
void version(uint8_t value);
void version(uint8_t new_version);

/**
* \brief Sets the packet type field.
* \param value The new packet type to be set.
*/
void packet_type(uint8_t value);
void packet_type(uint8_t new_ptype);

/**
* \brief Sets the length field.
* \param value The new length to be set.
*/
void length(uint16_t value);
void length(uint16_t new_length);

/**
* \brief Sets the type field.
* \param value The new type to be set.
*/
void type(uint8_t value);
void type(uint8_t new_type);

/**
* \brief Getter for the PDU's type.
Expand Down Expand Up @@ -297,7 +297,7 @@ class TINS_API RC4EAPOL : public EAPOL {
* \brief Sets the key length field.
* \param value The new key length to be set.
*/
void key_length(uint16_t value);
void key_length(uint16_t length);

/**
* \brief Sets the replay counter field.
Expand All @@ -309,31 +309,31 @@ class TINS_API RC4EAPOL : public EAPOL {
* \brief Sets the key IV field.
* \param value The new key IV to be set.
*/
void key_iv(const uint8_t* value);
void key_iv(const uint8_t* ptr);

/**
* \brief Sets the key flag field.
* \param value The new key flag to be set.
*/
void key_flag(small_uint<1> value);
void key_flag(small_uint<1> flag);

/**
* \brief Sets the key index field.
* \param value The new key index to be set.
*/
void key_index(small_uint<7> value);
void key_index(small_uint<7> new_key_index);

/**
* \brief Sets the key signature field.
* \param value The new key signature to be set.
*/
void key_sign(const uint8_t* value);
void key_sign(const uint8_t* ptr);

/**
* \brief Sets the key field.
* \param value The new key to be set.
*/
void key(const key_type& value);
void key(const key_type& new_key);

/* Virtual method override. */

Expand Down Expand Up @@ -618,13 +618,13 @@ class TINS_API RSNEAPOL : public EAPOL {
* \brief Sets the key length field.
* \param value The new key length to be set.
*/
void key_length(uint16_t value);
void key_length(uint16_t length);

/**
* \brief Sets the replay counter field.
* \param value The new replay counter to be set.
*/
void replay_counter(uint64_t value);
void replay_counter(uint64_t new_replay_counter);

/**
* \brief Sets the key IV field.
Expand Down Expand Up @@ -692,13 +692,13 @@ class TINS_API RSNEAPOL : public EAPOL {
* \brief Setter for the key_mic field.
* \param value The new to be set.
*/
void key_mic(small_uint<1> value);
void key_mic(small_uint<1> flag);

/**
* \brief Setter for the secure field.
* \param value The new to be set.
*/
void secure(small_uint<1> value);
void secure(small_uint<1> flag);

/**
* \brief Setter for the error field.
Expand All @@ -722,7 +722,7 @@ class TINS_API RSNEAPOL : public EAPOL {
* \brief Setter for the key_descriptor field.
* \param value The new to be set.
*/
void key_descriptor(small_uint<3> value);
void key_descriptor(small_uint<3> new_key_descriptor);

/**
* \brief Setter for the key_t field.
Expand Down
2 changes: 1 addition & 1 deletion src/address_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ IPv6Range operator/(const IPv6Address& addr, int mask) {
return IPv6Range::from_mask(addr, IPv6Address::from_prefix_length(mask));
}

} // Tins
} // namespace Tins
8 changes: 4 additions & 4 deletions src/arp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ ARP::ARP(ipaddress_type target_ip,
const hwaddress_type& target_hw,
const hwaddress_type& sender_hw)
: header_() {
hw_addr_format((uint16_t)Constants::ARP::ETHER);
prot_addr_format((uint16_t)Constants::Ethernet::IP);
hw_addr_format(static_cast<uint16_t>(Constants::ARP::ETHER));
prot_addr_format(static_cast<uint16_t>(Constants::Ethernet::IP));
hw_addr_length(Tins::EthernetII::address_type::address_size);
prot_addr_length(4 /* IP address size */);
sender_ip_addr(sender_ip);
Expand Down Expand Up @@ -119,7 +119,7 @@ bool ARP::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
if (total_sz < sizeof(header_)) {
return false;
}
const arp_header* arp_ptr = (const arp_header*)ptr;
const arp_header* arp_ptr = reinterpret_cast<const arp_header*>(ptr);
return arp_ptr->sender_ip_address == header_.target_ip_address &&
arp_ptr->target_ip_address == header_.sender_ip_address;
}
Expand Down Expand Up @@ -150,4 +150,4 @@ EthernetII ARP::make_arp_reply(ipaddress_type target,
return EthernetII(hw_tgt, hw_snd) / arp;
}

} // Tins
} // namespace Tins
4 changes: 2 additions & 2 deletions src/bootp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ bool BootP::matches_response(const uint8_t* ptr, uint32_t total_sz) const {
if (total_sz < sizeof(bootp_)) {
return false;
}
const bootp_header* bootp_ptr = (const bootp_header *)ptr;
const bootp_header* bootp_ptr = reinterpret_cast<const bootp_header *>(ptr);
return bootp_ptr->xid == bootp_.xid;
}

} // Tins
} // namespace Tins
26 changes: 13 additions & 13 deletions src/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class byte_array {
uint8_t data[n];
};

} // Internals
} // namespace Internals

namespace Crypto {

Expand Down Expand Up @@ -228,7 +228,7 @@ struct RC4Key {
static RC4Key from_packet(const Dot11Data& dot11, const RawPDU& raw,
const vector<uint8_t>& ptk) {
const RawPDU::payload_type& pload = raw.payload();
const uint8_t* tk = &ptk[0] + 32;
const uint8_t* tk = ptk.data() + 32;
Internals::byte_array<16> rc4_key;
uint16_t ppk[6];
const Dot11::address_type addr = dot11.addr2();
Expand Down Expand Up @@ -367,7 +367,7 @@ PDU* WEPDecrypter::decrypt(RawPDU& raw, const string& password) {
RC4Key key(key_buffer_.begin(), key_buffer_.begin() + password.size() + 3);
rc4(pload.begin() + 4, pload.end(), key, pload.begin());
uint32_t payload_size = static_cast<uint32_t>(pload.size() - 8);
uint32_t crc = Utils::crc32(&pload[0], payload_size);
uint32_t crc = Utils::crc32(pload.data(), payload_size);
if (pload[pload.size() - 8] != (crc & 0xff) ||
pload[pload.size() - 7] != ((crc >> 8) & 0xff) ||
pload[pload.size() - 6] != ((crc >> 16) & 0xff) ||
Expand All @@ -376,7 +376,7 @@ PDU* WEPDecrypter::decrypt(RawPDU& raw, const string& password) {
}

try {
return new SNAP(&pload[0], payload_size);
return new SNAP(pload.data(), payload_size);
}
catch (exception_base&) {
return 0;
Expand Down Expand Up @@ -448,16 +448,16 @@ SessionKeys::SessionKeys(const RSNHandshake& hs, const pmk_type& pmk)
}
for (int i(0); i < 4; ++i) {
PKE[99] = i;
HMAC(EVP_sha1(), &pmk[0], pmk.size(), PKE, 100, &ptk_[0] + i * 20, 0);
HMAC(EVP_sha1(), pmk.data(), pmk.size(), PKE, 100, (ptk_).data() + i * 20, 0);
}
RSNEAPOL& last_hs = const_cast<RSNEAPOL&>(hs.handshake()[3]);
PDU::serialization_type buffer = last_hs.serialize();
fill(buffer.begin() + 81, buffer.begin() + 81 + 16, 0);
if (is_ccmp_) {
HMAC(EVP_sha1(), &ptk_[0], 16, &buffer[0], buffer.size(), MIC, 0);
HMAC(EVP_sha1(), ptk_.data(), 16, buffer.data(), buffer.size(), MIC, 0);
}
else {
HMAC(EVP_md5(), &ptk_[0], 16, &buffer[0], buffer.size(), MIC, 0);
HMAC(EVP_md5(), ptk_.data(), 16, buffer.data(), buffer.size(), MIC, 0);
}

if (!equal(MIC, MIC + RSNEAPOL::mic_size, last_hs.mic())) {
Expand All @@ -479,7 +479,7 @@ SNAP* SessionKeys::ccmp_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) con

uint8_t AAD[32] = {0};
AAD[0] = 0;
AAD[1] = 22 + 6 * int(dot11.from_ds() && dot11.to_ds());
AAD[1] = 22 + 6 * static_cast<int>(dot11.from_ds() && dot11.to_ds());
if (dot11.subtype() == Dot11::QOS_DATA_DATA) {
AAD[1] += 2;
}
Expand All @@ -498,7 +498,7 @@ SNAP* SessionKeys::ccmp_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) con
}

AES_KEY ctx;
AES_set_encrypt_key(&ptk_[0] + 32, 128, &ctx);
AES_set_encrypt_key(ptk_.data() + 32, 128, &ctx);
uint8_t crypted_block[16];
size_t total_sz = raw.payload_size() - 16, offset = 8, blocks = (total_sz + 15) / 16;

Expand Down Expand Up @@ -544,7 +544,7 @@ SNAP* SessionKeys::ccmp_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) con
offset += block_sz;
}
if (equal(nice_MIC, nice_MIC + sizeof(nice_MIC), MIC)) {
return new SNAP(&pload[0], total_sz);
return new SNAP(pload.data(), total_sz);
}
else {
return 0;
Expand All @@ -560,15 +560,15 @@ SNAP* SessionKeys::tkip_decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) con
RawPDU::payload_type& pload = raw.payload();
rc4(pload.begin() + 8, pload.end(), key, pload.begin());

uint32_t crc = Utils::crc32(&pload[0], pload.size() - 12);
uint32_t crc = Utils::crc32(pload.data(), pload.size() - 12);
if (pload[pload.size() - 12] != (crc & 0xff) ||
pload[pload.size() - 11] != ((crc >> 8) & 0xff) ||
pload[pload.size() - 10] != ((crc >> 16) & 0xff) ||
pload[pload.size() - 9] != ((crc >> 24) & 0xff)) {
return 0;
}

return new SNAP(&pload[0], pload.size() - 20);
return new SNAP(pload.data(), pload.size() - 20);
}

SNAP* SessionKeys::decrypt_unicast(const Dot11Data& dot11, RawPDU& raw) const {
Expand Down Expand Up @@ -596,7 +596,7 @@ SupplicantData::SupplicantData(const string& psk, const string& ssid)
ssid.size(),
4096,
pmk_.size(),
&pmk_[0]
pmk_.data()
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/detail/address_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,5 @@ IPv6Address last_address_from_mask(IPv6Address addr, const IPv6Address& mask) {
return addr;
}

} // Internals
} // Tins
} // namespace Internals
} // namespace Tins
4 changes: 2 additions & 2 deletions src/detail/icmp_extension_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ void try_parse_icmp_extensions(InputMemoryStream& stream,
}
}

} // Internals
} // Tins
} // namespace Internals
} // namespace Tins
4 changes: 2 additions & 2 deletions src/detail/pdu_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,5 +299,5 @@ PDU::PDUType ip_type_to_pdu_flag(Constants::IP::e flag) {
};
}

} // Internals
} // Tins
} // namespace Internals
} // namespace Tins
4 changes: 2 additions & 2 deletions src/detail/sequence_number_helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ int seq_compare(uint32_t seq1, uint32_t seq2) {
}
}

} // Internals
} // Tins
} // namespace Internals
} // namespace Tins
Loading