Skip to content

Commit

Permalink
apply suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: jparisu <[email protected]>
  • Loading branch information
jparisu committed Jun 20, 2023
1 parent 00b2761 commit 96b94dc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
14 changes: 9 additions & 5 deletions src/cpp/security/accesscontrol/DistinguishedName.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace fastrtps {
namespace rtps {
namespace security {

namespace details {
namespace detail {

Attribute::Attribute(
const DistinguishedName& name)
Expand Down Expand Up @@ -216,12 +216,16 @@ Attribute Attribute::cut(
return res;
}

std::ostream& operator<<(std::ostream& os, const Attribute& att)
{
os.write(att.value, att.length);
return os;
}

bool DistinguishedNameSpecialized::compare(
const DistinguishedName& name1,
const DistinguishedName& name2) noexcept
{
DistinguishedNameSpecialized dns1(name1);
DistinguishedNameSpecialized dns2(name2);
return DistinguishedNameSpecialized(name1) == DistinguishedNameSpecialized(name2);
}

Expand Down Expand Up @@ -374,13 +378,13 @@ bool DistinguishedNameSpecialized::operator ==(
return true;
}

} //namespace details
} //namespace detail

bool rfc2253_string_compare(
const DistinguishedName& name1,
const DistinguishedName& name2)
{
return details::DistinguishedNameSpecialized::compare(name1, name2);
return detail::DistinguishedNameSpecialized::compare(name1, name2);
}

} //namespace security
Expand Down
23 changes: 19 additions & 4 deletions src/cpp/security/accesscontrol/DistinguishedName.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ namespace security {
*
* ASN.1 representation of DistinguishedNames
* DistinguishedName ::= RDNSequence
*
* RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
*
* RelativeDistinguishedName ::= SET SIZE (1..MAX) OF
* AttributeTypeAndValue
*
* AttributeTypeAndValue ::= SEQUENCE {
* type AttributeType,
* value AttributeValue }
Expand All @@ -63,7 +66,7 @@ using DistinguishedName = std::string;
* Follow RFC 2253: https://datatracker.ietf.org/doc/html/rfc2253
* The idea here is that comparing 2 DistinguishedNames is not as trivial as comparing 2 strings,
* nor comparing its values splitting the string.
* The comparison must be a complex function that takes into account many specific details.
* The comparison must be a complex function that takes into account many specific detail.
*
* So far, Fast DDS gives 2 strings (in some format that we assume is the correct one) and this compares
* whether the two strings refer to the same DistinguishedName.
Expand All @@ -74,7 +77,7 @@ using DistinguishedName = std::string;
* @warning this function does not correctly fulfilled all requirements of RFC 2253.
* Requirements that are not fulfilled:
* - multi-attribute
* - types accept oid
* - types accept void
* - assumes that input is a well formed DistinguishedName following rfc2253
* @todo make this function complete (probably better by implementing DistinguishedName class).
*
Expand All @@ -89,8 +92,17 @@ bool rfc2253_string_compare(
const DistinguishedName& name2);


namespace details {
namespace detail {

/**
* @brief Struct that stores a const char* and a size, referencing a string without dynamic allocation.
*
* This struct is only an auxiliary class to implement \c rfc2253_string_compare .
* This class is not meant to be used outside this function.
*
* The necessity of this class is due to comparing two key-value format strings without allocate heap memory.
* Thus, it implements string formatter functions only using char ptr and size.
*/
struct Attribute
{
Attribute() = default;
Expand Down Expand Up @@ -138,6 +150,9 @@ struct Attribute
size_t length {0};
};

//! To string method for Attribute
std::ostream& operator<<(std::ostream& os, const Attribute& att);

/**
* @brief This class is only used to compare 2 DistinguishedName.
*
Expand Down Expand Up @@ -191,7 +206,7 @@ class DistinguishedNameSpecialized
size_t size_ {0};
};

} //namespace details
} //namespace detail

} //namespace security
} //namespace rtps
Expand Down

0 comments on commit 96b94dc

Please sign in to comment.