pub fn parse_sni(input: &[u8]) -> Result<Option<ServerId>, Incomplete> {
    let r = untrusted::Input::from(input).read_all(untrusted::EndOfInput, |input| {
        let r = extract_sni(input);
        input.skip_to_end(); // Ignore anything after what we parsed.
        r
    });
    match r {
        Ok(Some(sni)) => {
            let sni = match std::str::from_utf8(sni.as_slice_less_safe())
                .ok()
                .and_then(|n| n.parse::<id::Name>().ok())
            {
                Some(sni) => sni,
                None => return Ok(None),
            };
            trace!(?sni, "parse_sni: parsed correctly up to SNI");
            Ok(Some(ServerId(sni)))
        }
        Ok(None) => {
            trace!("parse_sni: failed to parse up to SNI");
            Ok(None)
        }
        Err(untrusted::EndOfInput) => {
            trace!("parse_sni: needs more input");
            Err(Incomplete)
        }
    }
}
/// Determines whether the given `input` looks like the start of a TLS connection.
///
/// The determination is made based on whether the input looks like (the start of) a valid
/// ClientHello that a reasonable TLS client might send, and the SNI matches the given identity.
///
/// XXX: Once the TLS record header is matched, the determination won't be made until the entire TLS
/// record including the entire ClientHello handshake message is available.
///
/// TODO: Reject non-matching inputs earlier.
///
/// This assumes that the ClientHello is small and is sent in a single TLS record, which is what all
/// reasonable implementations do. (If they were not to, they wouldn't interoperate with picky
/// servers.)
Determines whether the given `input` looks like the start of a TLS connection.
The determination is made based on whether the input looks like (the start of) a valid
ClientHello that a reasonable TLS client might send, and the SNI matches the given identity.

Once the TLS record header is matched, the determination won't be made until the entire TLS
record including the entire ClientHello handshake message is available.

Reject non-matching inputs earlier.

This assumes that the ClientHello is small and is sent in a single TLS record, which is what all
reasonable implementations do. (If they were not to, they wouldn't interoperate with picky
servers.)
Determines whether the given ` input ` looks like the start of a TLS connection . The determination is made based on whether the input looks like ( the start of ) a valid ClientHello that a reasonable TLS client might send and the SNI matches the given identity . Once the TLS record header is matched the determination won ' t be made until the entire TLS record including the entire ClientHello handshake message is available . Reject non - matching inputs earlier . This assumes that the ClientHello is small and is sent in a single TLS record which is what all reasonable implementations do . ( If they were not to they wouldn ' t interoperate with picky servers . )
pub fn parse_sni(input: &[u8]) -> Result<Option<ServerId>, Incomplete> {
    let r = untrusted::Input::from(input).read_all(untrusted::EndOfInput, |input| {
        let r = extract_sni(input);
        input.skip_to_end(); // Ignore anything after what we parsed.
        r
    });
    match r {
        Ok(Some(sni)) => {
            let sni = match std::str::from_utf8(sni.as_slice_less_safe())
                .ok()
                .and_then(|n| n.parse::<id::Name>().ok())
            {
                Some(sni) => sni,
                None => return Ok(None),
            };
            trace!(?sni, "parse_sni: parsed correctly up to SNI");
            Ok(Some(ServerId(sni)))
        }
        Ok(None) => {
            trace!("parse_sni: failed to parse up to SNI");
            Ok(None)
        }
        Err(untrusted::EndOfInput) => {
            trace!("parse_sni: needs more input");
            Err(Incomplete)
        }
    }
}
pub fn parse_sni ( input : & [ u8 ] ) -> Result < Option < ServerId > , Incomplete > { let r = untrusted :: Input :: from ( input ) . read_all ( untrusted :: EndOfInput , | input | { let r = extract_sni ( input ) ; input . skip_to_end ( ) ; // Ignore anything after what we parsed. r } ) ; match r { Ok ( Some ( sni ) ) => { let sni = match std :: str :: from_utf8 ( sni . as_slice_less_safe ( ) ) . ok ( ) . and_then ( | n | n . parse :: < id :: Name > ( ) . ok ( ) ) { Some ( sni ) => sni , None => return Ok ( None ) , } ; trace ! ( sni " " ) ; Ok ( Some ( ServerId ( sni ) ) ) } Ok ( None ) => { trace ! ( " " ) ; Ok ( None ) } Err ( untrusted :: EndOfInput ) => { trace ! ( " " ) ; Err ( Incomplete ) } } }
Determines whether the given `input` looks like the start of a TLS connection.
Determines whether the given ` input ` looks like the start of a TLS connection .
input
&[u8]
input
&[u8]