Skip to content

Commit

Permalink
fix(ldap): correct tag handing in Decoder and Encoder impls for LdapS…
Browse files Browse the repository at this point in the history
…tring (#369)

closes #368

Co-authored-by: David Blatter <[email protected]>
  • Loading branch information
dablach and David Blatter authored Nov 12, 2024
1 parent fbf8268 commit 66c7d4e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions standards/ldap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub type MessageId = u32;
/// We can use Rust `String` type to represent this type, see
/// <https://github.com/librasn/rasn/issues/304> and <https://www.unicode.org/faq/unicode_iso.html>
#[derive(AsnType, Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[rasn(tag(universal, 4))]
pub struct LdapString(pub String);

impl core::ops::Deref for LdapString {
Expand Down Expand Up @@ -61,11 +62,11 @@ impl rasn::Encode for LdapString {
fn encode_with_tag_and_constraints<EN: rasn::Encoder>(
&self,
encoder: &mut EN,
_tag: rasn::types::Tag,
tag: rasn::types::Tag,
constraints: rasn::types::Constraints,
) -> core::result::Result<(), EN::Error> {
encoder.encode_octet_string(
rasn::types::Tag::OCTET_STRING,
tag,
constraints,
self.0.as_bytes(),
)?;
Expand All @@ -75,10 +76,10 @@ impl rasn::Encode for LdapString {
impl rasn::Decode for LdapString {
fn decode_with_tag_and_constraints<D: rasn::Decoder>(
decoder: &mut D,
_tag: rasn::types::Tag,
tag: rasn::types::Tag,
constraints: rasn::types::Constraints,
) -> core::result::Result<Self, D::Error> {
String::from_utf8(decoder.decode_octet_string(rasn::types::Tag::OCTET_STRING, constraints)?)
String::from_utf8(decoder.decode_octet_string(tag, constraints)?)
.map_err(|error| {
rasn::de::Error::custom(
alloc::format!("LdapString not valid UTF-8: {error}"),
Expand Down

0 comments on commit 66c7d4e

Please sign in to comment.