@@ -88,10 +88,17 @@ use super::{Answer, Offer};
8888/// ## Usage
8989///
9090/// ```rust
91- /// use mina_p2p::webrtc::{ConnectionAuth, Offer, Answer};
92- ///
91+ /// # use p2p::webrtc::{ConnectionAuth, Offer, Answer};
92+ /// # use p2p::identity::{SecretKey, PublicKey};
93+ /// # use rand::thread_rng;
94+ /// # fn example(offer: &Offer, answer: &Answer,
95+ /// # my_secret_key: &SecretKey, peer_public_key: &PublicKey)
96+ /// # -> Option<()> {
97+ /// # let mut rng = thread_rng();
9398/// let connection_auth = ConnectionAuth::new(&offer, &answer);
94- /// let encrypted_auth = connection_auth.encrypt(&my_secret_key, &peer_public_key, rng)?;
99+ /// let encrypted_auth = connection_auth.encrypt(&my_secret_key, &peer_public_key, &mut rng)?;
100+ /// # Some(())
101+ /// # }
95102/// ```
96103#[ derive( Serialize , Deserialize , Debug , Eq , PartialEq , Clone ) ]
97104pub struct ConnectionAuth ( Vec < u8 > ) ;
@@ -124,9 +131,16 @@ pub struct ConnectionAuth(Vec<u8>);
124131/// ## Example
125132///
126133/// ```rust
134+ /// # use p2p::webrtc::ConnectionAuthEncrypted;
135+ /// # use p2p::identity::{SecretKey, PublicKey};
136+ /// # fn example(encrypted_auth: &ConnectionAuthEncrypted,
137+ /// # my_secret_key: &SecretKey, peer_public_key: &PublicKey)
138+ /// # -> Option<()> {
127139/// // After receiving encrypted authentication data
128140/// let decrypted_auth = encrypted_auth.decrypt(&my_secret_key, &peer_public_key)?;
129141/// // Verify that the decrypted data matches expected values
142+ /// # Some(())
143+ /// # }
130144/// ```
131145#[ derive( Debug , Clone ) ]
132146pub struct ConnectionAuthEncrypted ( Box < [ u8 ; 92 ] > ) ;
@@ -158,10 +172,11 @@ impl ConnectionAuth {
158172 /// # Example
159173 ///
160174 /// ```rust
161- /// use mina_p2p ::webrtc::ConnectionAuth;
162- ///
175+ /// # use p2p ::webrtc::{ ConnectionAuth, Offer, Answer} ;
176+ /// # fn example(offer: &Offer, answer: &Answer) {
163177 /// let auth = ConnectionAuth::new(&offer, &answer);
164178 /// // Use auth for connection verification
179+ /// # }
165180 /// ```
166181 pub fn new ( offer : & Offer , answer : & Answer ) -> Self {
167182 Self ( [ offer. sdp_hash ( ) , answer. sdp_hash ( ) ] . concat ( ) )
@@ -196,14 +211,18 @@ impl ConnectionAuth {
196211 /// # Example
197212 ///
198213 /// ```rust
199- /// use rand::thread_rng;
200- ///
214+ /// # use p2p::webrtc::ConnectionAuth;
215+ /// # use p2p::identity::{SecretKey, PublicKey};
216+ /// # use rand::thread_rng;
217+ /// # fn example(connection_auth: &ConnectionAuth,
218+ /// # my_secret_key: &SecretKey, peer_public_key: &PublicKey) {
201219 /// let mut rng = thread_rng();
202220 /// let encrypted_auth = connection_auth.encrypt(&my_secret_key, &peer_public_key, &mut rng);
203221 ///
204222 /// if let Some(encrypted) = encrypted_auth {
205223 /// // Send encrypted authentication data to peer
206224 /// }
225+ /// # }
207226 /// ```
208227 pub fn encrypt (
209228 & self ,
@@ -254,6 +273,10 @@ impl ConnectionAuthEncrypted {
254273 /// # Example
255274 ///
256275 /// ```rust
276+ /// # use p2p::webrtc::ConnectionAuthEncrypted;
277+ /// # use p2p::identity::{SecretKey, PublicKey};
278+ /// # fn example(encrypted_auth: &ConnectionAuthEncrypted,
279+ /// # my_secret_key: &SecretKey, peer_public_key: &PublicKey) {
257280 /// // After receiving encrypted authentication data from peer
258281 /// if let Some(decrypted_auth) = encrypted_auth.decrypt(&my_secret_key, &peer_public_key) {
259282 /// // Authentication successful, proceed with connection
@@ -262,6 +285,7 @@ impl ConnectionAuthEncrypted {
262285 /// // Authentication failed, reject connection
263286 /// println!("Peer authentication failed");
264287 /// }
288+ /// # }
265289 /// ```
266290 pub fn decrypt ( & self , sec_key : & SecretKey , other_pk : & PublicKey ) -> Option < ConnectionAuth > {
267291 sec_key
0 commit comments