File tree Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Expand file tree Collapse file tree 1 file changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -8,8 +8,8 @@ use Secp256k1;
8
8
pub use self :: std_only:: * ;
9
9
10
10
/// A trait for all kinds of Context's that Lets you define the exact flags and a function to deallocate memory.
11
- /// * DO NOT * implement it for your own types .
12
- pub unsafe trait Context {
11
+ /// It shouldn't be possible to implement this for types outside this crate .
12
+ pub unsafe trait Context : private :: Sealed {
13
13
/// Flags for the ffi.
14
14
const FLAGS : c_uint ;
15
15
/// A constant description of the context.
@@ -39,8 +39,24 @@ pub struct AllPreallocated<'buf> {
39
39
phantom : PhantomData < & ' buf ( ) > ,
40
40
}
41
41
42
+ mod private {
43
+ use super :: * ;
44
+ // A trick to prevent users from implementing a trait.
45
+ // on one hand this trait is public, on the other it's in a private module
46
+ // so it's not visible to anyone besides it's parent (the context module)
47
+ pub trait Sealed { }
48
+
49
+ impl < ' buf > Sealed for AllPreallocated < ' buf > { }
50
+ impl < ' buf > Sealed for VerifyOnlyPreallocated < ' buf > { }
51
+ impl < ' buf > Sealed for SignOnlyPreallocated < ' buf > { }
52
+ }
53
+
42
54
#[ cfg( feature = "std" ) ]
43
55
mod std_only {
56
+ impl private:: Sealed for SignOnly { }
57
+ impl private:: Sealed for All { }
58
+ impl private:: Sealed for VerifyOnly { }
59
+
44
60
use super :: * ;
45
61
46
62
/// Represents the set of capabilities needed for signing.
You can’t perform that action at this time.
0 commit comments