@@ -2,7 +2,8 @@ use anyhow::Result;
2
2
use atty:: Stream ;
3
3
use biscuit_auth:: {
4
4
builder:: { BiscuitBuilder , BlockBuilder , Rule , Term } ,
5
- Authorizer , ThirdPartyRequest , UnverifiedBiscuit , { PrivateKey , PublicKey } ,
5
+ Algorithm , Authorizer , AuthorizerBuilder , PrivateKey , PublicKey , ThirdPartyRequest ,
6
+ UnverifiedBiscuit ,
6
7
} ;
7
8
use chrono:: { DateTime , Duration , Utc } ;
8
9
use parse_duration as duration_parser;
@@ -131,8 +132,8 @@ pub fn read_authority_from(
131
132
from : & DatalogInput ,
132
133
all_params : & [ Param ] ,
133
134
context : & Option < String > ,
134
- builder : & mut BiscuitBuilder ,
135
- ) -> Result < ( ) > {
135
+ builder : BiscuitBuilder ,
136
+ ) -> Result < BiscuitBuilder > {
136
137
let string = match from {
137
138
DatalogInput :: FromEditor => read_editor_string ( ) ?,
138
139
DatalogInput :: FromStdin => read_stdin_string ( "datalog program" ) ?,
@@ -153,22 +154,22 @@ pub fn read_authority_from(
153
154
}
154
155
}
155
156
156
- builder
157
- . add_code_with_params ( & string, params, scope_params)
157
+ let mut builder = builder
158
+ . code_with_params ( & string, params, scope_params)
158
159
. map_err ( |e| ParseError ( "datalog statements" . to_string ( ) , e. to_string ( ) ) ) ?;
159
160
if let Some ( ctx) = context {
160
- builder. set_context ( ctx. to_owned ( ) ) ;
161
+ builder = builder . context ( ctx. to_owned ( ) ) ;
161
162
}
162
163
163
- Ok ( ( ) )
164
+ Ok ( builder )
164
165
}
165
166
166
167
pub fn read_block_from (
167
168
from : & DatalogInput ,
168
169
all_params : & [ Param ] ,
169
170
context : & Option < String > ,
170
- builder : & mut BlockBuilder ,
171
- ) -> Result < ( ) > {
171
+ builder : BlockBuilder ,
172
+ ) -> Result < BlockBuilder > {
172
173
let string = match from {
173
174
DatalogInput :: FromEditor => read_editor_string ( ) ?,
174
175
DatalogInput :: FromStdin => read_stdin_string ( "datalog program" ) ?,
@@ -188,22 +189,22 @@ pub fn read_block_from(
188
189
}
189
190
}
190
191
}
191
- builder
192
- . add_code_with_params ( & string, params, scope_params)
192
+ let mut builder = builder
193
+ . code_with_params ( & string, params, scope_params)
193
194
. map_err ( |e| ParseError ( "datalog statements" . to_string ( ) , e. to_string ( ) ) ) ?;
194
195
195
196
if let Some ( ctx) = context {
196
- builder. set_context ( ctx. to_owned ( ) ) ;
197
+ builder = builder . context ( ctx. to_owned ( ) ) ;
197
198
}
198
199
199
- Ok ( ( ) )
200
+ Ok ( builder )
200
201
}
201
202
202
203
pub fn read_authorizer_from (
203
204
from : & DatalogInput ,
204
205
all_params : & [ Param ] ,
205
- authorizer : & mut Authorizer ,
206
- ) -> Result < ( ) > {
206
+ builder : AuthorizerBuilder ,
207
+ ) -> Result < AuthorizerBuilder > {
207
208
let string = match from {
208
209
DatalogInput :: FromEditor => read_editor_string ( ) ?,
209
210
DatalogInput :: FromStdin => read_stdin_string ( "datalog program" ) ?,
@@ -223,14 +224,14 @@ pub fn read_authorizer_from(
223
224
}
224
225
}
225
226
}
226
- authorizer
227
- . add_code_with_params ( & string, params, scope_params)
227
+ let builder = builder
228
+ . code_with_params ( & string, params, scope_params)
228
229
. map_err ( |e| ParseError ( "datalog statements" . to_string ( ) , e. to_string ( ) ) ) ?;
229
230
230
- Ok ( ( ) )
231
+ Ok ( builder )
231
232
}
232
233
233
- pub fn read_private_key_from ( from : & KeyBytes ) -> Result < PrivateKey > {
234
+ pub fn read_private_key_from ( from : & KeyBytes , alg : Algorithm ) -> Result < PrivateKey > {
234
235
let bytes = match from {
235
236
KeyBytes :: FromStdin ( KeyFormat :: RawBytes ) => read_stdin_bytes ( ) ?,
236
237
KeyBytes :: FromStdin ( KeyFormat :: HexKey ) => {
@@ -246,11 +247,11 @@ pub fn read_private_key_from(from: &KeyBytes) -> Result<PrivateKey> {
246
247
) ?,
247
248
KeyBytes :: HexString ( str) => hex:: decode ( str) ?,
248
249
} ;
249
- PrivateKey :: from_bytes ( & bytes)
250
+ PrivateKey :: from_bytes ( & bytes, alg )
250
251
. map_err ( |e| ParseError ( "private key" . to_string ( ) , format ! ( "{}" , & e) ) . into ( ) )
251
252
}
252
253
253
- pub fn read_public_key_from ( from : & KeyBytes ) -> Result < PublicKey > {
254
+ pub fn read_public_key_from ( from : & KeyBytes , alg : Algorithm ) -> Result < PublicKey > {
254
255
let bytes = match from {
255
256
KeyBytes :: FromStdin ( KeyFormat :: RawBytes ) => read_stdin_bytes ( ) ?,
256
257
KeyBytes :: FromStdin ( KeyFormat :: HexKey ) => {
@@ -266,7 +267,7 @@ pub fn read_public_key_from(from: &KeyBytes) -> Result<PublicKey> {
266
267
) ?,
267
268
KeyBytes :: HexString ( str) => hex:: decode ( str) ?,
268
269
} ;
269
- PublicKey :: from_bytes ( & bytes)
270
+ PublicKey :: from_bytes ( & bytes, alg )
270
271
. map_err ( |e| ParseError ( "public key" . to_string ( ) , format ! ( "{}" , & e) ) . into ( ) )
271
272
}
272
273
@@ -424,7 +425,7 @@ pub fn parse_param(kv: &str) -> Result<Param, std::io::Error> {
424
425
) ) ?;
425
426
let bytes =
426
427
hex:: decode ( hex_key) . map_err ( |e| Error :: new ( ErrorKind :: Other , format ! ( "{}" , & e) ) ) ;
427
- let pubkey = PublicKey :: from_bytes ( & bytes?)
428
+ let pubkey = PublicKey :: from_bytes ( & bytes?, Algorithm :: Ed25519 )
428
429
. map_err ( |e| Error :: new ( ErrorKind :: Other , format ! ( "{}" , & e) ) ) ?;
429
430
Ok ( Param :: PublicKey ( name. to_string ( ) , pubkey) )
430
431
} ,
0 commit comments