Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
b3947ab
The 'type' functions declaration added, the 'add' function declaratio…
HelenMamontova Sep 16, 2025
f974e43
Return values of functions 'name' and 'code' changed, the 'type' func…
HelenMamontova Sep 16, 2025
90257d6
The "string" parameter added to call add function when checking the
HelenMamontova Sep 16, 2025
e7d19c9
The BOOST_CHECK_EQUAL and BOOST_CHECK_THROW commands to check the 'type'
HelenMamontova Sep 17, 2025
aba8c0f
BOOST_CHECK_EQUAL command to check the 'type' functions of BasicDicti…
HelenMamontova Sep 17, 2025
94816a8
BOOST_CHECK_EQUAL command to check the 'type' functions of BasicDicti…
HelenMamontova Sep 18, 2025
72d390c
BOOST_CHECK_EQUAL command to check the 'type' functions of BasicDicti…
HelenMamontova Sep 18, 2025
354f0bb
BOOST_AUTO_TEST_SUITE(VendorDictionaryTests) added.
HelenMamontova Sep 19, 2025
9415fcb
Header file <iostream> added. Check for attribute type added to
HelenMamontova Sep 30, 2025
33d7ed2
BOOST_CHECK_EQUAL, BOOST_CHECK_THROW to check 'type' function added in
HelenMamontova Sep 30, 2025
052b78f
Variable name type changed to code. Function name type() changed to c…
HelenMamontova Oct 3, 2025
4abe923
Enum name Attribute_Types changed to Attribute_Codes.
HelenMamontova Oct 3, 2025
e570671
The value invalidAttributeType changed to invalidAttributeCode in enum
HelenMamontova Oct 3, 2025
b46802a
Parameter type changed to code. Function type() changed to code(). Cl…
HelenMamontova Oct 3, 2025
dd5fb87
Parameter vendorType changed to vendorAttributeCode. Function vendorT…
HelenMamontova Oct 3, 2025
994f022
Header file "attribute_types" changed to "attribute_codes". Function …
HelenMamontova Oct 3, 2025
63dbc71
Varisble type changed to code. Function type() changed to code(). Cla…
HelenMamontova Oct 3, 2025
36175ab
Case Error::invalidAttributeType changed to Error::invalidAttributeCode
HelenMamontova Oct 3, 2025
9f6595c
Header file "attribute_types.h" changed to "attribute_codes.h". Funct…
HelenMamontova Oct 3, 2025
6bfd01d
Function packetTypeToString changed to packetCodeToString. Parameter
HelenMamontova Oct 3, 2025
e4a5b02
Header file "attribute_types.h" changed to "attribute_codes.h".
HelenMamontova Oct 3, 2025
8bad86b
Header file "attribute_types.h" changed to "attribute_codes.h". Funct…
HelenMamontova Oct 3, 2025
0176725
Function type() changed to code(). Function vendorType() changed to
HelenMamontova Oct 3, 2025
01c53d8
Header file "attribute_types.h" changed to "attribute_codes.h". Function
HelenMamontova Oct 3, 2025
c288274
Header file "attribute_types.h" changed to "attribute_codes.h". Funct…
HelenMamontova Oct 3, 2025
5532d57
Parameter type changed to code. Function type() changed to code().
HelenMamontova Oct 3, 2025
7c6b585
Header file "attribute_types.h" changed to "attribute_codes.h". Param…
HelenMamontova Oct 3, 2025
df8335b
The element suchAttributeNameWithAnotherTypeAlreadyExists added to enum
HelenMamontova Oct 6, 2025
c6ddcbf
The case Error::suchAttributeNameWithAnotherTypeAlreadyExists added to
HelenMamontova Oct 6, 2025
21cb71c
The Exception messages fixed in the functions BasicDictionary::append
HelenMamontova Oct 6, 2025
e50e375
Debugging std::cout removed and other debugging std::cout added.
HelenMamontova Oct 23, 2025
cc339fa
Functions attributeType added to class Dictionaries.
HelenMamontova Nov 6, 2025
e3604b1
The tests changed to check attribute types.
HelenMamontova Nov 6, 2025
bad45c1
Code changed to correctly fill the dictionaries and getting attribute
HelenMamontova Nov 6, 2025
de23cf0
The flag variable, emplace function call removed in the function add.
HelenMamontova Nov 12, 2025
a9877fd
The flag variable added, check flag added, check if types are differe…
HelenMamontova Nov 12, 2025
ce989bf
The flag variable initialization changed in function BasicDictionary:…
HelenMamontova Nov 12, 2025
4b7b07e
The flag variable initialization changed, the condition
HelenMamontova Nov 12, 2025
e8a27ee
The flag variable initialization changed, break command added in cycle
HelenMamontova Nov 12, 2025
7422054
Variable flag, function emplace call removed in functions
HelenMamontova Nov 13, 2025
4141211
Code for determining the attribute type when the flag is set added to
HelenMamontova Nov 19, 2025
a12acfc
Code for checking the attribute type when the flag is set added to
HelenMamontova Nov 19, 2025
c988a04
Attribute User-Password changed, attribute abc added for checking the…
HelenMamontova Nov 19, 2025
4187f10
The attrName, attrType variables declaration moved to constructin if
HelenMamontova Nov 21, 2025
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
30 changes: 15 additions & 15 deletions include/radproto/attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ namespace RadProto
class Attribute
{
public:
Attribute(uint8_t type);
Attribute(uint8_t code);
virtual ~Attribute() = default;
uint8_t type() const { return m_type; }
uint8_t code() const { return m_code; }
virtual std::string toString() const = 0;
virtual std::vector<uint8_t> toVector(const std::string& secret, const std::array<uint8_t, 16>& auth) const = 0;
virtual Attribute* clone() const = 0;
private:
uint8_t m_type;
uint8_t m_code;
};

class String: public Attribute
{
public:
String(uint8_t type, const uint8_t* data, size_t size);
String(uint8_t type, const std::string& string);
String(uint8_t code, const uint8_t* data, size_t size);
String(uint8_t code, const std::string& string);
std::string toString() const override { return m_value; }
std::vector<uint8_t> toVector(const std::string& secret, const std::array<uint8_t, 16>& auth) const override;
String* clone() const override;
Expand All @@ -35,8 +35,8 @@ namespace RadProto
class Integer: public Attribute
{
public:
Integer(uint8_t type, const uint8_t* data, size_t size);
Integer(uint8_t type, uint32_t value);
Integer(uint8_t code, const uint8_t* data, size_t size);
Integer(uint8_t code, uint32_t value);
std::string toString() const override;
std::vector<uint8_t> toVector(const std::string& secret, const std::array<uint8_t, 16>& auth) const override;
Integer* clone() const override;
Expand All @@ -47,8 +47,8 @@ namespace RadProto
class IpAddress : public Attribute
{
public:
IpAddress(uint8_t type, const uint8_t* data, size_t size);
IpAddress(uint8_t type, const std::array<uint8_t, 4>& address);
IpAddress(uint8_t code, const uint8_t* data, size_t size);
IpAddress(uint8_t code, const std::array<uint8_t, 4>& address);
std::string toString() const override;
std::vector<uint8_t> toVector(const std::string& secret, const std::array<uint8_t, 16>& auth) const override;
IpAddress* clone() const override;
Expand All @@ -59,8 +59,8 @@ namespace RadProto
class Encrypted : public Attribute
{
public:
Encrypted (uint8_t type, const uint8_t* data, size_t size, const std::string& secret, const std::array<uint8_t, 16>& auth);
Encrypted(uint8_t type, const std::string& password);
Encrypted (uint8_t code, const uint8_t* data, size_t size, const std::string& secret, const std::array<uint8_t, 16>& auth);
Encrypted(uint8_t code, const std::string& password);
std::string toString() const override { return m_value; }
std::vector<uint8_t> toVector(const std::string& secret, const std::array<uint8_t, 16>& auth) const override;
Encrypted* clone() const override;
Expand All @@ -71,8 +71,8 @@ namespace RadProto
class Bytes: public Attribute
{
public:
Bytes(uint8_t type, const uint8_t* data, size_t size);
Bytes(uint8_t type, const std::vector<uint8_t>& bytes);
Bytes(uint8_t code, const uint8_t* data, size_t size);
Bytes(uint8_t code, const std::vector<uint8_t>& bytes);
std::string toString() const override;
std::vector<uint8_t> toVector(const std::string& secret, const std::array<uint8_t, 16>& auth) const override;
Bytes* clone() const override;
Expand All @@ -83,8 +83,8 @@ namespace RadProto
class ChapPassword: public Attribute
{
public:
ChapPassword(uint8_t type, const uint8_t* data, size_t size);
ChapPassword(uint8_t type, uint8_t chapId, const std::vector<uint8_t>& chapValue);
ChapPassword(uint8_t code, const uint8_t* data, size_t size);
ChapPassword(uint8_t code, uint8_t chapId, const std::vector<uint8_t>& chapValue);
std::string toString() const override;
uint8_t chapId() const { return m_chapId; }
std::vector<uint8_t> chapValue() const { return m_value; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace RadProto
{
enum Attribute_Types
enum Attribute_Codes
{
USER_NAME = 1,
USER_PASSWORD = 2,
Expand Down
25 changes: 22 additions & 3 deletions include/radproto/dictionaries.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,25 @@ namespace RadProto
BasicDictionary() = default;
std::string name(uint32_t code) const;
uint32_t code(const std::string& name) const;
void add(uint32_t code, const std::string& name);
std::string type(uint32_t code) const;
std::string type(const std::string& name) const;

void add(uint32_t code, const std::string& name, const std::string& type);
void append(const BasicDictionary& basicDict);
private:
std::map<uint32_t, std::pair<std::string, std::string>> m_rightDict;
std::map<std::string, std::pair<uint32_t, std::string>> m_reverseDict;
};

class VendorDictionary
{
public:
VendorDictionary() = default;
std::string name(uint32_t code) const;
uint32_t code(const std::string& name) const;

void add(uint32_t code, const std::string& name);
void append(const VendorDictionary& vendorDict);
private:
std::map<uint32_t, std::string> m_rightDict;
std::map<std::string, uint32_t> m_reverseDict;
Expand All @@ -38,13 +55,15 @@ namespace RadProto
Dictionaries(const std::string& filePath);
void append(const Dictionaries& fillingDictionaries);
const BasicDictionary& attributes() const { return m_attributes; }
const BasicDictionary& vendorNames() const { return m_vendorNames; }
const VendorDictionary& vendorNames() const { return m_vendorNames; }
const DependentDictionary& attributeValues() const { return m_attributeValues; }
const DependentDictionary& vendorAttributes() const { return m_vendorAttributes; }
const DependentDictionary& vendorAttributeValues() const { return m_vendorAttributeValues; }

std::string attributeName(uint32_t code) const;
uint32_t attributeCode(const std::string& name) const;
std::string attributeType(uint32_t code) const;
std::string attributeType(const std::string name) const;

std::string vendorName(uint32_t code) const;
uint32_t vendorCode(const std::string& name) const;
Expand All @@ -60,7 +79,7 @@ namespace RadProto

private:
BasicDictionary m_attributes;
BasicDictionary m_vendorNames;
VendorDictionary m_vendorNames;
DependentDictionary m_attributeValues;
DependentDictionary m_vendorAttributes;
DependentDictionary m_vendorAttributeValues;
Expand Down
5 changes: 3 additions & 2 deletions include/radproto/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ namespace RadProto
numberOfBytesIsLessThan20,
requestLengthIsShort,
eapMessageAttributeError,
invalidAttributeType,
invalidAttributeCode,
invalidAttributeSize,
invalidVendorSpecificAttributeId,
suchAttributeNameAlreadyExists,
suchAttributeCodeAlreadyExists
suchAttributeCodeAlreadyExists,
suchAttributeNameWithAnotherTypeAlreadyExists
};

class Exception: public std::runtime_error
Expand Down
6 changes: 3 additions & 3 deletions include/radproto/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ namespace RadProto
{
public:
Packet(const uint8_t* buffer, size_t size, const std::string& secret);
Packet(uint8_t type, uint8_t id, const std::array<uint8_t, 16>& auth, const std::vector<Attribute*>& attributes, const std::vector<VendorSpecific>& vendorSpecific);
Packet(uint8_t code, uint8_t id, const std::array<uint8_t, 16>& auth, const std::vector<Attribute*>& attributes, const std::vector<VendorSpecific>& vendorSpecific);
Packet(const Packet& other);
~Packet();
uint8_t type() const { return m_type; }
uint8_t code() const { return m_code; }
uint8_t id() const { return m_id; };
const std::array<uint8_t, 16>& auth() const { return m_auth; }
const std::vector<Attribute*>& attributes() const { return m_attributes; }
const std::vector<VendorSpecific>& vendorSpecific() const { return m_vendorSpecific; }
const std::vector<uint8_t> makeSendBuffer(const std::string& secret) const;

private:
uint8_t m_type;
uint8_t m_code;
uint8_t m_id;
bool m_recalcAuth;
std::array<uint8_t, 16> m_auth;
Expand Down
6 changes: 3 additions & 3 deletions include/radproto/vendor_attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ namespace RadProto
{
public:
VendorSpecific(const uint8_t* data);
VendorSpecific(uint32_t vendorId, uint8_t vendorType, const std::vector<uint8_t>& vendorValue);
VendorSpecific(uint32_t vendorId, uint8_t vendorAttributeCode, const std::vector<uint8_t>& vendorValue);
std::string toString() const;
uint8_t vendorType() const { return m_vendorType; }
uint8_t vendorAttributeCode() const { return m_vendorAttributeCode; }
uint32_t vendorId() const { return m_vendorId; }
std::vector<uint8_t> toVector() const;
private:
uint32_t m_vendorId;
uint8_t m_vendorType;
uint8_t m_vendorAttributeCode;
std::vector<uint8_t> m_value;
};
}
6 changes: 3 additions & 3 deletions sample/server.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "server.h"
#include "packet_codes.h"
#include "attribute_types.h"
#include "attribute_codes.h"
#include <functional>
#include <iostream>

Expand Down Expand Up @@ -37,11 +37,11 @@ RadProto::Packet Server::makeResponse(const RadProto::Packet& request)
std::string userName;
for (const auto& attribute : request.attributes())
{
if (attribute->type() == RadProto::USER_NAME)
if (attribute->code() == RadProto::USER_NAME)
userName = attribute->toString();
}

if (request.type() == RadProto::ACCESS_REQUEST && userName == "test")
if (request.code() == RadProto::ACCESS_REQUEST && userName == "test")
return RadProto::Packet(RadProto::ACCESS_ACCEPT, request.id(), request.auth(), attributes, vendorSpecific);

return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributes, vendorSpecific);
Expand Down
Loading
Loading