Skip to content

Commit 3a595d8

Browse files
committed
gss-api: add GeneralStringRef placeholder
1 parent 959d2ec commit 3a595d8

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

gss-api/src/negotiation.rs

+41-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Negotiation-related types
22
use der::{
3-
Choice, Enumerated, Sequence,
3+
Choice, DecodeValue, EncodeValue, Enumerated, FixedTag, Sequence, Tag,
44
asn1::{BitString, OctetStringRef},
55
};
66

@@ -295,14 +295,8 @@ pub enum NegState {
295295
#[derive(Clone, Copy, Debug, Eq, PartialEq, Sequence)]
296296
pub struct NegHints<'a> {
297297
/// SHOULD<5> contain the string "not_defined_in_RFC4178@please_ignore".
298-
/// This is currently `OctetStringRef` as `GeneralString` is not part of the `der` crate
299-
#[asn1(
300-
context_specific = "0",
301-
optional = "true",
302-
tag_mode = "IMPLICIT",
303-
constructed = "true"
304-
)]
305-
pub hint_name: Option<OctetStringRef<'a>>, // TODO: GeneralString
298+
#[asn1(context_specific = "0", optional = "true")]
299+
pub hint_name: Option<GeneralStringRef<'a>>, // TODO: der GeneralString
306300

307301
/// 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.
308302
///
@@ -311,6 +305,37 @@ pub struct NegHints<'a> {
311305
pub hint_address: Option<OctetStringRef<'a>>,
312306
}
313307

308+
/// This is currently `OctetStringRef` as `GeneralString` is not part of the `der` crate
309+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
310+
pub struct GeneralStringRef<'a> {
311+
/// Raw contents, unchecked
312+
pub contents: OctetStringRef<'a>,
313+
}
314+
impl FixedTag for GeneralStringRef<'_> {
315+
const TAG: Tag = Tag::GeneralString;
316+
}
317+
impl<'a> DecodeValue<'a> for GeneralStringRef<'a> {
318+
type Error = der::Error;
319+
320+
fn decode_value<R: der::Reader<'a>>(
321+
reader: &mut R,
322+
header: der::Header,
323+
) -> Result<Self, Self::Error> {
324+
Ok(Self {
325+
contents: OctetStringRef::decode_value(reader, header)?,
326+
})
327+
}
328+
}
329+
impl EncodeValue for GeneralStringRef<'_> {
330+
fn value_len(&self) -> der::Result<der::Length> {
331+
self.contents.value_len()
332+
}
333+
334+
fn encode_value(&self, encoder: &mut impl der::Writer) -> der::Result<()> {
335+
self.contents.encode_value(encoder)
336+
}
337+
}
338+
314339
/// `NegTokenInit2` as defined in [MS-SPNG Section 2.2.1].
315340
///
316341
/// ```text
@@ -389,7 +414,13 @@ mod tests {
389414
);
390415
assert_eq!(
391416
b"not_defined_in_RFC4178@please_ignore",
392-
&neg_token.neg_hints.unwrap().hint_name.unwrap().as_bytes()[2..]
417+
&neg_token
418+
.neg_hints
419+
.unwrap()
420+
.hint_name
421+
.unwrap()
422+
.contents
423+
.as_bytes()
393424
);
394425
}
395426

0 commit comments

Comments
 (0)