Skip to content

Commit 8364eb5

Browse files
dishmakerbaloo
andauthored
gss-api: change NegHints::hint_name to GeneralStringRef type (#1779)
* der: add minimal GeneralStringRef type Co-authored-by: Arthur Gautier <[email protected]>
1 parent 3f7b96f commit 8364eb5

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

der/src/asn1.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod bmp_string;
1111
mod boolean;
1212
mod choice;
1313
mod context_specific;
14+
mod general_string;
1415
mod generalized_time;
1516
mod ia5_string;
1617
mod integer;
@@ -35,6 +36,7 @@ pub use self::{
3536
bit_string::{BitStringIter, BitStringRef},
3637
choice::Choice,
3738
context_specific::{ContextSpecific, ContextSpecificRef},
39+
general_string::GeneralStringRef,
3840
generalized_time::GeneralizedTime,
3941
ia5_string::Ia5StringRef,
4042
integer::{int::IntRef, uint::UintRef},

der/src/asn1/general_string.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use crate::{BytesRef, DecodeValue, EncodeValue, FixedTag, Header, Length, Reader, Tag, Writer};
2+
3+
/// This is currently `&[u8]` internally, as `GeneralString` is not fully implemented yet
4+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5+
pub struct GeneralStringRef<'a> {
6+
/// Raw contents, unchecked
7+
inner: BytesRef<'a>,
8+
}
9+
impl<'a> GeneralStringRef<'a> {
10+
/// This is currently `&[u8]` internally, as `GeneralString` is not fully implemented yet
11+
pub fn as_bytes(&self) -> &'a [u8] {
12+
self.inner.as_slice()
13+
}
14+
}
15+
16+
impl FixedTag for GeneralStringRef<'_> {
17+
const TAG: Tag = Tag::GeneralString;
18+
}
19+
impl<'a> DecodeValue<'a> for GeneralStringRef<'a> {
20+
type Error = crate::Error;
21+
22+
fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self, Self::Error> {
23+
Ok(Self {
24+
inner: BytesRef::decode_value(reader, header)?,
25+
})
26+
}
27+
}
28+
impl EncodeValue for GeneralStringRef<'_> {
29+
fn value_len(&self) -> crate::Result<Length> {
30+
self.inner.value_len()
31+
}
32+
33+
fn encode_value(&self, encoder: &mut impl Writer) -> crate::Result<()> {
34+
self.inner.encode_value(encoder)
35+
}
36+
}

gss-api/src/negotiation.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Negotiation-related types
22
use der::{
3-
AnyRef, Choice, Enumerated, Sequence,
4-
asn1::{BitString, OctetStringRef},
3+
Choice, Enumerated, Sequence,
4+
asn1::{BitString, GeneralStringRef, OctetStringRef},
55
};
66

77
use crate::MechType;
@@ -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 `AnyRef` 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<AnyRef<'a>>, // TODO: GeneralString
298+
#[asn1(context_specific = "0", optional = "true")]
299+
pub hint_name: Option<GeneralStringRef<'a>>,
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
///
@@ -389,7 +383,7 @@ mod tests {
389383
);
390384
assert_eq!(
391385
b"not_defined_in_RFC4178@please_ignore",
392-
&neg_token.neg_hints.unwrap().hint_name.unwrap().value()[2..]
386+
&neg_token.neg_hints.unwrap().hint_name.unwrap().as_bytes()
393387
);
394388
}
395389

0 commit comments

Comments
 (0)