@@ -627,7 +627,7 @@ impl Ed25519 {
627627 /// # Parameters
628628 ///
629629 /// * `hash`: Message digest to sign.
630- /// * `context`: Buffer containing context for which hash is being signed.
630+ /// * `context`: Optional buffer containing context for which hash is being signed.
631631 /// * `signature`: Output buffer to hold signature.
632632 ///
633633 /// # Returns
@@ -655,16 +655,21 @@ impl Ed25519 {
655655 /// ];
656656 /// let context = b"context";
657657 /// let mut signature = [0u8; Ed25519::SIG_SIZE];
658- /// ed.sign_hash_ph(&hash, context, &mut signature).expect("Error with sign_hash_ph()");
658+ /// ed.sign_hash_ph(&hash, Some( context) , &mut signature).expect("Error with sign_hash_ph()");
659659 /// ```
660- pub fn sign_hash_ph ( & mut self , hash : & [ u8 ] , context : & [ u8 ] , signature : & mut [ u8 ] ) -> Result < usize , i32 > {
660+ pub fn sign_hash_ph ( & mut self , hash : & [ u8 ] , context : Option < & [ u8 ] > , signature : & mut [ u8 ] ) -> Result < usize , i32 > {
661661 let hash_size = hash. len ( ) as u32 ;
662- let context_size = context. len ( ) as u8 ;
662+ let mut context_ptr: * const u8 = core:: ptr:: null ( ) ;
663+ let mut context_size = 0u8 ;
664+ if let Some ( context) = context {
665+ context_ptr = context. as_ptr ( ) ;
666+ context_size = context. len ( ) as u8 ;
667+ }
663668 let mut signature_size = signature. len ( ) as u32 ;
664669 let rc = unsafe {
665670 ws:: wc_ed25519ph_sign_hash ( hash. as_ptr ( ) , hash_size,
666671 signature. as_mut_ptr ( ) , & mut signature_size, & mut self . ws_key ,
667- context . as_ptr ( ) , context_size)
672+ context_ptr , context_size)
668673 } ;
669674 if rc != 0 {
670675 return Err ( rc) ;
@@ -680,7 +685,7 @@ impl Ed25519 {
680685 /// # Parameters
681686 ///
682687 /// * `message`: Message digest to sign.
683- /// * `context`: Buffer containing context for which message is being signed.
688+ /// * `context`: Optional buffer containing context for which message is being signed.
684689 /// * `signature`: Output buffer to hold signature.
685690 ///
686691 /// # Returns
@@ -699,16 +704,21 @@ impl Ed25519 {
699704 /// let message = [0x42u8, 33, 55, 66];
700705 /// let context = b"context";
701706 /// let mut signature = [0u8; Ed25519::SIG_SIZE];
702- /// ed.sign_msg_ph(&message, context, &mut signature).expect("Error with sign_msg_ph()");
707+ /// ed.sign_msg_ph(&message, Some( context) , &mut signature).expect("Error with sign_msg_ph()");
703708 /// ```
704- pub fn sign_msg_ph ( & mut self , message : & [ u8 ] , context : & [ u8 ] , signature : & mut [ u8 ] ) -> Result < usize , i32 > {
709+ pub fn sign_msg_ph ( & mut self , message : & [ u8 ] , context : Option < & [ u8 ] > , signature : & mut [ u8 ] ) -> Result < usize , i32 > {
705710 let message_size = message. len ( ) as u32 ;
706- let context_size = context. len ( ) as u8 ;
711+ let mut context_ptr: * const u8 = core:: ptr:: null ( ) ;
712+ let mut context_size = 0u8 ;
713+ if let Some ( context) = context {
714+ context_ptr = context. as_ptr ( ) ;
715+ context_size = context. len ( ) as u8 ;
716+ }
707717 let mut signature_size = signature. len ( ) as u32 ;
708718 let rc = unsafe {
709719 ws:: wc_ed25519ph_sign_msg ( message. as_ptr ( ) , message_size,
710720 signature. as_mut_ptr ( ) , & mut signature_size, & mut self . ws_key ,
711- context . as_ptr ( ) , context_size)
721+ context_ptr , context_size)
712722 } ;
713723 if rc != 0 {
714724 return Err ( rc) ;
@@ -859,7 +869,7 @@ impl Ed25519 {
859869 ///
860870 /// * `signature`: Signature to verify.
861871 /// * `hash`: Message to verify the signature of.
862- /// * `context`: Buffer containing context for which the hash was signed.
872+ /// * `context`: Optional buffer containing context for which the hash was signed.
863873 ///
864874 /// # Returns
865875 ///
@@ -885,19 +895,24 @@ impl Ed25519 {
885895 /// ];
886896 /// let context = b"context";
887897 /// let mut signature = [0u8; Ed25519::SIG_SIZE];
888- /// ed.sign_hash_ph(&hash, context, &mut signature).expect("Error with sign_hash_ph()");
889- /// let signature_valid = ed.verify_hash_ph(&signature, &hash, context).expect("Error with verify_hash_ph()");
898+ /// ed.sign_hash_ph(&hash, Some( context) , &mut signature).expect("Error with sign_hash_ph()");
899+ /// let signature_valid = ed.verify_hash_ph(&signature, &hash, Some( context) ).expect("Error with verify_hash_ph()");
890900 /// assert!(signature_valid);
891901 /// ```
892- pub fn verify_hash_ph ( & mut self , signature : & [ u8 ] , hash : & [ u8 ] , context : & [ u8 ] ) -> Result < bool , i32 > {
902+ pub fn verify_hash_ph ( & mut self , signature : & [ u8 ] , hash : & [ u8 ] , context : Option < & [ u8 ] > ) -> Result < bool , i32 > {
893903 let signature_size = signature. len ( ) as u32 ;
894904 let hash_size = hash. len ( ) as u32 ;
895- let context_size = context. len ( ) as u8 ;
905+ let mut context_ptr: * const u8 = core:: ptr:: null ( ) ;
906+ let mut context_size = 0u8 ;
907+ if let Some ( context) = context {
908+ context_ptr = context. as_ptr ( ) ;
909+ context_size = context. len ( ) as u8 ;
910+ }
896911 let mut res = 0i32 ;
897912 let rc = unsafe {
898913 ws:: wc_ed25519ph_verify_hash ( signature. as_ptr ( ) , signature_size,
899914 hash. as_ptr ( ) , hash_size, & mut res, & mut self . ws_key ,
900- context . as_ptr ( ) , context_size)
915+ context_ptr , context_size)
901916 } ;
902917 if rc != 0 {
903918 return Err ( rc) ;
@@ -914,7 +929,7 @@ impl Ed25519 {
914929 ///
915930 /// * `signature`: Signature to verify.
916931 /// * `message`: Message to verify the signature of.
917- /// * `context`: Buffer containing context for which the message was signed.
932+ /// * `context`: Option buffer containing context for which the message was signed.
918933 ///
919934 /// # Returns
920935 ///
@@ -931,19 +946,24 @@ impl Ed25519 {
931946 /// let message = [0x42u8, 33, 55, 66];
932947 /// let context = b"context";
933948 /// let mut signature = [0u8; Ed25519::SIG_SIZE];
934- /// ed.sign_msg_ph(&message, context, &mut signature).expect("Error with sign_msg_ph()");
935- /// let signature_valid = ed.verify_msg_ph(&signature, &message, context).expect("Error with verify_msg_ph()");
949+ /// ed.sign_msg_ph(&message, Some( context) , &mut signature).expect("Error with sign_msg_ph()");
950+ /// let signature_valid = ed.verify_msg_ph(&signature, &message, Some( context) ).expect("Error with verify_msg_ph()");
936951 /// assert!(signature_valid);
937952 /// ```
938- pub fn verify_msg_ph ( & mut self , signature : & [ u8 ] , message : & [ u8 ] , context : & [ u8 ] ) -> Result < bool , i32 > {
953+ pub fn verify_msg_ph ( & mut self , signature : & [ u8 ] , message : & [ u8 ] , context : Option < & [ u8 ] > ) -> Result < bool , i32 > {
939954 let signature_size = signature. len ( ) as u32 ;
940955 let message_size = message. len ( ) as u32 ;
941- let context_size = context. len ( ) as u8 ;
956+ let mut context_ptr: * const u8 = core:: ptr:: null ( ) ;
957+ let mut context_size = 0u8 ;
958+ if let Some ( context) = context {
959+ context_ptr = context. as_ptr ( ) ;
960+ context_size = context. len ( ) as u8 ;
961+ }
942962 let mut res = 0i32 ;
943963 let rc = unsafe {
944964 ws:: wc_ed25519ph_verify_msg ( signature. as_ptr ( ) , signature_size,
945965 message. as_ptr ( ) , message_size, & mut res, & mut self . ws_key ,
946- context . as_ptr ( ) , context_size)
966+ context_ptr , context_size)
947967 } ;
948968 if rc != 0 {
949969 return Err ( rc) ;
0 commit comments