Skip to content

Commit f0c97e4

Browse files
refator: format code and fix tests;
1 parent 6723431 commit f0c97e4

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

src/lib.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,8 @@ where
608608
///
609609
/// # Parameters
610610
/// * `flags`: package-specific flags that indicate the quality of protection. A security package can use this parameter to enable the selection of cryptographic algorithms
611-
/// * `message`: On input, the structure references one or more `SecurityBuffer` structures of `type SecurityBufferType::Data` that contain the message to be signed,
612-
/// and a `SecurityBuffer` of type `SecurityBufferType::Token` that receives the signature.
611+
/// * `message`: On input, the structure references one or more `SecurityBufferRef` structures of type `BufferType::Data` that contain the message to be signed,
612+
/// and a `SecurityBufferRef` of type `BufferType::Token` that receives the signature.
613613
/// * `sequence_number`: the sequence number that the transport application assigned to the message. If the transport application does not maintain sequence numbers, this parameter must be zero
614614
///
615615
/// # Returns
@@ -627,8 +627,8 @@ where
627627
/// let mut client_ntlm = sspi::Ntlm::new();
628628
/// let mut ntlm = sspi::Ntlm::new();
629629
///
630-
/// let mut client_output_buffer = vec![sspi::OwnedSecurityBuffer::new(Vec::new(), sspi::SecurityBufferType::Token)];
631-
/// let mut server_output_buffer = vec![sspi::OwnedSecurityBuffer::new(Vec::new(), sspi::SecurityBufferType::Token)];
630+
/// let mut client_output_buffer = vec![sspi::SecurityBuffer::new(Vec::new(), sspi::BufferType::Token)];
631+
/// let mut server_output_buffer = vec![sspi::SecurityBuffer::new(Vec::new(), sspi::BufferType::Token)];
632632
///
633633
/// let identity = sspi::AuthIdentity {
634634
/// username: Username::parse("user").unwrap(),
@@ -691,8 +691,8 @@ where
691691
/// let mut token = [0; 128];
692692
/// let mut data = "This is a message to be signed".as_bytes().to_vec();
693693
/// let mut msg_buffer = vec![
694-
/// sspi::SecurityBufferRef::Token(token.as_mut_slice()),
695-
/// sspi::SecurityBufferRef::Data(data.as_mut_slice()),
694+
/// sspi::SecurityBufferRef::token_buf(token.as_mut_slice()),
695+
/// sspi::SecurityBufferRef::data_buf(data.as_mut_slice()),
696696
/// ];
697697
///
698698
/// println!("Input data: {:?}", msg_buffer[1].data());
@@ -706,14 +706,18 @@ where
706706
///
707707
/// # MSDN
708708
/// * [MakeSignature function](https://learn.microsoft.com/en-us/windows/win32/api/sspi/nf-sspi-makesignature)
709-
fn make_signature(&mut self, flags: u32, message: &mut [SecurityBufferRef], sequence_number: u32)
710-
-> crate::Result<()>;
709+
fn make_signature(
710+
&mut self,
711+
flags: u32,
712+
message: &mut [SecurityBufferRef],
713+
sequence_number: u32,
714+
) -> crate::Result<()>;
711715

712716
/// Verifies that a message signed by using the `make_signature` function was received in the correct sequence and has not been modified.
713717
///
714718
/// # Parameters
715-
/// * `message`: On input, the structure references one or more `SecurityBuffer` structures of `type SecurityBufferType::Data` that contain the message to be verified,
716-
/// and a `SecurityBuffer` of type `SecurityBufferType::Token` that contains the signature.
719+
/// * `message`: On input, the structure references one or more `SecurityBufferRef` structures of type `BufferType::Data` that contain the message to be verified,
720+
/// and a `SecurityBufferRef` of type `BufferType::Token` that contains the signature.
717721
/// * `sequence_number`: the sequence number that the transport application assigned to the message. If the transport application does not maintain sequence numbers, this parameter must be zero
718722
///
719723
/// # Returns
@@ -731,8 +735,8 @@ where
731735
/// let mut ntlm = sspi::Ntlm::new();
732736
/// let mut server_ntlm = sspi::Ntlm::new();
733737
///
734-
/// let mut client_output_buffer = vec![sspi::OwnedSecurityBuffer::new(Vec::new(), sspi::SecurityBufferType::Token)];
735-
/// let mut server_output_buffer = vec![sspi::OwnedSecurityBuffer::new(Vec::new(), sspi::SecurityBufferType::Token)];
738+
/// let mut client_output_buffer = vec![sspi::SecurityBuffer::new(Vec::new(), sspi::BufferType::Token)];
739+
/// let mut server_output_buffer = vec![sspi::SecurityBuffer::new(Vec::new(), sspi::BufferType::Token)];
736740
///
737741
/// let identity = sspi::AuthIdentity {
738742
/// username: Username::parse("user").unwrap(),
@@ -795,8 +799,8 @@ where
795799
/// let mut token = [0; 128];
796800
/// let mut data = "This is a message".as_bytes().to_vec();
797801
/// let mut msg = [
798-
/// sspi::SecurityBufferRef::Token(token.as_mut_slice()),
799-
/// sspi::SecurityBufferRef::Data(data.as_mut_slice()),
802+
/// sspi::SecurityBufferRef::token_buf(token.as_mut_slice()),
803+
/// sspi::SecurityBufferRef::data_buf(data.as_mut_slice()),
800804
/// ];
801805
///
802806
/// let _result = server_ntlm
@@ -805,8 +809,8 @@ where
805809
/// let [mut token, mut data] = msg;
806810
///
807811
/// let mut msg_buffer = vec![
808-
/// sspi::SecurityBufferRef::Token(token.take_data()),
809-
/// sspi::SecurityBufferRef::Data(data.take_data()),
812+
/// sspi::SecurityBufferRef::token_buf(token.take_data()),
813+
/// sspi::SecurityBufferRef::data_buf(data.take_data()),
810814
/// ];
811815
///
812816
/// #[allow(unused_variables)]

src/ntlm/test.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,16 @@ fn make_signature_verified_by_verify_signature() {
239239
let mut plain_test_data = TEST_DATA.to_vec();
240240
let mut signature_test_data = [0u8; 16];
241241
let mut make_signature_buffers = vec![
242-
SecurityBufferRef::Data(&mut plain_test_data),
243-
SecurityBufferRef::Token(&mut signature_test_data),
242+
SecurityBufferRef::data_buf(&mut plain_test_data),
243+
SecurityBufferRef::token_buf(&mut signature_test_data),
244244
];
245245
assert!(sender
246246
.make_signature(0, &mut make_signature_buffers, TEST_SEQ_NUM)
247247
.is_ok());
248248

249249
let mut verify_signature_buffers = vec![
250-
SecurityBufferRef::Data(&mut plain_test_data),
251-
SecurityBufferref::Token(&mut signature_test_data),
250+
SecurityBufferRef::data_buf(&mut plain_test_data),
251+
SecurityBufferRef::token_buf(&mut signature_test_data),
252252
];
253253
assert!(reciever
254254
.verify_signature(&mut verify_signature_buffers, TEST_SEQ_NUM)
@@ -267,7 +267,10 @@ fn verify_signature_fails_on_invalid_signature() {
267267
0x01, 0x00, 0x00, 0x00, 0x2e, 0xdf, 0xff, 0x61, 0x29, 0xd6, 0x4d, 0xa9, 0xd2, 0x02, 0x96, 0x49,
268268
];
269269

270-
let mut verify_signature_buffers = vec![SecurityBuffer::Data(&mut test_data), SecurityBuffer::Token(&mut token)];
270+
let mut verify_signature_buffers = vec![
271+
SecurityBufferRef::data_buf(&mut test_data),
272+
SecurityBufferRef::token_buf(&mut token),
273+
];
271274
assert!(context
272275
.verify_signature(&mut verify_signature_buffers, TEST_SEQ_NUM)
273276
.is_err());

0 commit comments

Comments
 (0)