Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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: 2 additions & 0 deletions der/src/asn1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod bmp_string;
mod boolean;
mod choice;
mod context_specific;
mod general_string;
mod generalized_time;
mod ia5_string;
mod integer;
Expand All @@ -35,6 +36,7 @@ pub use self::{
bit_string::{BitStringIter, BitStringRef},
choice::Choice,
context_specific::{ContextSpecific, ContextSpecificRef},
general_string::GeneralStringRef,
generalized_time::GeneralizedTime,
ia5_string::Ia5StringRef,
integer::{int::IntRef, uint::UintRef},
Expand Down
30 changes: 30 additions & 0 deletions der/src/asn1/general_string.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use crate::{BytesRef, DecodeValue, EncodeValue, FixedTag, Header, Length, Reader, Tag, Writer};

/// This is currently `OctetStringRef` internally, as `GeneralString` is not fully implemented yet
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct GeneralStringRef<'a> {
/// Raw contents, unchecked
#[doc(hidden)]
pub __contents: &'a [u8],
Comment thread
dishmaker marked this conversation as resolved.
Outdated
}
impl FixedTag for GeneralStringRef<'_> {
const TAG: Tag = Tag::GeneralString;
}
impl<'a> DecodeValue<'a> for GeneralStringRef<'a> {
type Error = crate::Error;

fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self, Self::Error> {
Ok(Self {
__contents: BytesRef::decode_value(reader, header)?.as_slice(),
})
}
}
impl EncodeValue for GeneralStringRef<'_> {
fn value_len(&self) -> crate::Result<Length> {
BytesRef::new(self.__contents)?.value_len()
}

fn encode_value(&self, encoder: &mut impl Writer) -> crate::Result<()> {
BytesRef::new(self.__contents)?.encode_value(encoder)
}
}
16 changes: 5 additions & 11 deletions gss-api/src/negotiation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Negotiation-related types
use der::{
AnyRef, Choice, Enumerated, Sequence,
asn1::{BitString, OctetStringRef},
Choice, Enumerated, Sequence,
asn1::{BitString, GeneralStringRef, OctetStringRef},
};

use crate::MechType;
Expand Down Expand Up @@ -295,14 +295,8 @@ pub enum NegState {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Sequence)]
pub struct NegHints<'a> {
/// SHOULD<5> contain the string "not_defined_in_RFC4178@please_ignore".
/// This is currently `AnyRef` as `GeneralString` is not part of the `der` crate
#[asn1(
context_specific = "0",
optional = "true",
tag_mode = "IMPLICIT",
constructed = "true"
)]
pub hint_name: Option<AnyRef<'a>>, // TODO: GeneralString
#[asn1(context_specific = "0", optional = "true")]
pub hint_name: Option<GeneralStringRef<'a>>,

/// Never present. MUST be omitted by the sender. Note that the encoding rules, as specified in [X690], require that this structure not be present at all, not just be zero.
///
Expand Down Expand Up @@ -389,7 +383,7 @@ mod tests {
);
assert_eq!(
b"not_defined_in_RFC4178@please_ignore",
&neg_token.neg_hints.unwrap().hint_name.unwrap().value()[2..]
&neg_token.neg_hints.unwrap().hint_name.unwrap().__contents
);
}

Expand Down