File tree Expand file tree Collapse file tree 5 files changed +74
-2
lines changed Expand file tree Collapse file tree 5 files changed +74
-2
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ impl Stream for BytesStream {
4343        self :  Pin < & mut  Self > , 
4444        _cx :  & mut  std:: task:: Context < ' _ > , 
4545    )  -> Poll < Option < Self :: Item > >  { 
46-         let  mut   self_mut = self . get_mut ( ) ; 
46+         let  self_mut = self . get_mut ( ) ; 
4747
4848        // we return all the available bytes in one call. 
4949        if  self_mut. bytes_read  < self_mut. bytes . len ( )  { 
@@ -75,7 +75,7 @@ impl AsyncRead for BytesStream {
7575        _cx :  & mut  std:: task:: Context < ' _ > , 
7676        buf :  & mut  [ u8 ] , 
7777    )  -> Poll < std:: io:: Result < usize > >  { 
78-         let  mut   self_mut = self . get_mut ( ) ; 
78+         let  self_mut = self . get_mut ( ) ; 
7979
8080        if  self_mut. bytes_read  < self_mut. bytes . len ( )  { 
8181            let  bytes_read = self_mut. bytes_read ; 
Original file line number Diff line number Diff line change @@ -85,4 +85,19 @@ impl KeyClient {
8585    { 
8686        EncryptBuilder :: new ( self . clone ( ) ,  name. into ( ) ,  encrypt_parameters) 
8787    } 
88+ 
89+     /// Get the requested number of bytes containing random values from a managed HSM. 
90+      /// 
91+      /// The `count` parameter is limited to a range between 1 and 128 inclusive. 
92+      /// 
93+      /// This operation requires the `rng` permission to be granted to the HSM. Furthermore, 
94+      /// it is only valid for clients that have been built using HSM URLs. 
95+      /// 
96+      /// POST {managedHsmBaseUrl}/rng?api-version=7.4 
97+      pub  fn  get_random_bytes < N > ( & self ,  hsm_name :  N ,  count :  u8 )  -> GetRandomBytesBuilder 
98+     where 
99+         N :  Into < String > , 
100+     { 
101+         GetRandomBytesBuilder :: new ( self . clone ( ) ,  hsm_name. into ( ) ,  count) 
102+     } 
88103} 
Original file line number Diff line number Diff line change @@ -403,3 +403,10 @@ pub struct EncryptResult {
403403    ) ]  
404404    pub  result :  Vec < u8 > , 
405405} 
406+ 
407+ #[ derive( Debug ,  Deserialize ) ]  
408+ pub  struct  GetRandomBytesResult  { 
409+     /// `value` is encoded as a base64url string. 
410+      #[ serde( rename = "value" ,  deserialize_with = "deser_base64" ) ]  
411+     pub  result :  Vec < u8 > , 
412+ } 
Original file line number Diff line number Diff line change 1+ use  crate :: prelude:: * ; 
2+ use  azure_core:: { headers:: Headers ,  CollectedResponse ,  Method } ; 
3+ use  serde_json:: { Map ,  Value } ; 
4+ 
5+ operation !  { 
6+     GetRandomBytes , 
7+     client:  KeyClient , 
8+     hsm_name:  String , 
9+     count:  u8 , 
10+ } 
11+ 
12+ impl  GetRandomBytesBuilder  { 
13+     pub  fn  into_future ( mut  self )  -> GetRandomBytes  { 
14+         Box :: pin ( async  move  { 
15+             // POST {HSMBaseUrl}//rng?api-version=7.4 
16+             let  vault_url = format ! ( "https://{}.managedhsm.azure.net/" ,  self . hsm_name) ; 
17+             let  mut  uri = url:: Url :: parse ( & vault_url) ?; 
18+             let  path = "rng" . to_string ( ) ; 
19+ 
20+             uri. set_path ( & path) ; 
21+ 
22+             let  mut  request_body = Map :: new ( ) ; 
23+             request_body. insert ( "count" . to_owned ( ) ,  Value :: from ( self . count ) ) ; 
24+ 
25+             let  headers = Headers :: new ( ) ; 
26+             let  mut  request = self . client . keyvault_client . finalize_request ( 
27+                 uri, 
28+                 Method :: Post , 
29+                 headers, 
30+                 Some ( Value :: Object ( request_body) . to_string ( ) . into ( ) ) , 
31+             ) ?; 
32+ 
33+             let  response = self 
34+                 . client 
35+                 . keyvault_client 
36+                 . send ( & mut  self . context ,  & mut  request) 
37+                 . await ?; 
38+ 
39+             let  response = CollectedResponse :: from_response ( response) . await ?; 
40+             let  body = response. body ( ) ; 
41+ 
42+             let  result = serde_json:: from_slice :: < GetRandomBytesResult > ( body) ?; 
43+             Ok ( result) 
44+         } ) 
45+     } 
46+ } 
47+ 
48+ type  GetRandomBytesResponse  = GetRandomBytesResult ; 
Original file line number Diff line number Diff line change 11mod  decrypt; 
22mod  encrypt; 
33mod  get_key; 
4+ mod  get_random_bytes; 
45mod  sign; 
56pub  use  decrypt:: * ; 
67pub  use  encrypt:: * ; 
78pub  use  get_key:: * ; 
9+ pub  use  get_random_bytes:: * ; 
810pub  use  sign:: * ; 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments