use opcua_crypto::SecurityPolicy;
use opcua_types::{ByteString, MessageSecurityMode};
use crate::comms::secure_channel::*;
#[test]
fn secure_channel_nonce_basic128rsa15() {
let mut sc = SecureChannel::new_no_certificate_store();
sc.set_security_mode(MessageSecurityMode::SignAndEncrypt);
sc.set_security_policy(SecurityPolicy::Basic128Rsa15);
assert!(sc
.validate_secure_channel_nonce_length(&ByteString::null())
.is_err());
assert!(sc
.validate_secure_channel_nonce_length(&ByteString::from(b""))
.is_err());
assert!(sc
.validate_secure_channel_nonce_length(&ByteString::from(b"1"))
.is_err());
assert!(sc
.validate_secure_channel_nonce_length(&ByteString::from(b"012345678901234"))
.is_err());
assert!(sc
.validate_secure_channel_nonce_length(&ByteString::from(b"01234567890123456"))
.is_err());
assert!(sc
.validate_secure_channel_nonce_length(&ByteString::from(
b"01234567890123456789012345678901".as_ref()
))
.is_err());
assert!(sc
.validate_secure_channel_nonce_length(&ByteString::from(b"0123456789012345"))
.is_ok());
}
#[test]
fn secure_channel_nonce_basic256() {
let mut sc = SecureChannel::new_no_certificate_store();
sc.set_security_mode(MessageSecurityMode::SignAndEncrypt);
sc.set_security_policy(SecurityPolicy::Basic256);
assert!(sc
.validate_secure_channel_nonce_length(&ByteString::null())
.is_err());
assert!(sc
.validate_secure_channel_nonce_length(&ByteString::from(b""))
.is_err());
assert!(sc
.validate_secure_channel_nonce_length(&ByteString::from(b"1"))
.is_err());
assert!(sc
.validate_secure_channel_nonce_length(&ByteString::from(b"0123456789012345678901234567890"))
.is_err());
assert!(sc
.validate_secure_channel_nonce_length(&ByteString::from(
b"012345678901234567890123456789012".as_ref()
))
.is_err());
assert!(sc
.validate_secure_channel_nonce_length(&ByteString::from(
b"01234567890123456789012345678901"
))
.is_ok());
}
#[test]
fn secure_channel_nonce_none() {
let mut sc = SecureChannel::new_no_certificate_store();
sc.set_security_mode(MessageSecurityMode::None);
sc.set_security_policy(SecurityPolicy::None);
assert!(sc
.validate_secure_channel_nonce_length(&ByteString::from(
b"01234567890123456789012345678901"
))
.is_ok());
assert!(sc
.validate_secure_channel_nonce_length(&ByteString::from(b"012"))
.is_ok());
assert!(sc
.validate_secure_channel_nonce_length(&ByteString::from(b""))
.is_ok());
}