@@ -751,6 +751,41 @@ mod tests {
751751 unsafe { ffi:: secp256k1_context_destroy ( ctx_full) } ;
752752 }
753753
754+ #[ test]
755+ fn test_raw_ctx ( ) {
756+ let ctx_full = Secp256k1 :: new ( ) ;
757+ let ctx_sign = Secp256k1 :: signing_only ( ) ;
758+ let ctx_vrfy = Secp256k1 :: verification_only ( ) ;
759+
760+ let full = unsafe { Secp256k1 :: from_raw_all ( ctx_full. ctx ) } ;
761+ let sign = unsafe { Secp256k1 :: from_raw_signining_only ( ctx_sign. ctx ) } ;
762+ let vrfy = unsafe { Secp256k1 :: from_raw_verification_only ( ctx_vrfy. ctx ) } ;
763+
764+ let ( sk, pk) = full. generate_keypair ( & mut thread_rng ( ) ) ;
765+ let msg = Message :: from_slice ( & [ 2u8 ; 32 ] ) . unwrap ( ) ;
766+ // Try signing
767+ assert_eq ! ( sign. sign( & msg, & sk) , full. sign( & msg, & sk) ) ;
768+ let sig = full. sign ( & msg, & sk) ;
769+
770+ // Try verifying
771+ assert ! ( vrfy. verify( & msg, & sig, & pk) . is_ok( ) ) ;
772+ assert ! ( full. verify( & msg, & sig, & pk) . is_ok( ) ) ;
773+
774+ drop ( full) ; drop ( sign) ; drop ( vrfy) ;
775+ drop ( ctx_full) ; drop ( ctx_sign) ; drop ( ctx_vrfy) ;
776+ }
777+
778+ #[ test]
779+ #[ should_panic]
780+ fn test_panic_raw_ctx ( ) {
781+ let ctx_vrfy = Secp256k1 :: verification_only ( ) ;
782+ let raw_ctx_verify_as_full = unsafe { Secp256k1 :: from_raw_all ( ctx_vrfy. ctx ) } ;
783+ let ( sk, _) = raw_ctx_verify_as_full. generate_keypair ( & mut thread_rng ( ) ) ;
784+ let msg = Message :: from_slice ( & [ 2u8 ; 32 ] ) . unwrap ( ) ;
785+ // Try signing
786+ raw_ctx_verify_as_full. sign ( & msg, & sk) ;
787+ }
788+
754789 #[ test]
755790 fn test_preallocation ( ) {
756791 let mut buf_ful = vec ! [ 0u8 ; Secp256k1 :: preallocate_size( ) ] ;
0 commit comments