jsonprooftoken/
encoding.rs

1// Copyright 2025 Fondazione LINKS
2
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6
7//     http://www.apache.org/licenses/LICENSE-2.0
8
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use data_encoding::BASE64URL_NOPAD;
16use serde::Serialize;
17
18pub enum SerializationType {
19    COMPACT,
20    JSON,
21    CBOR,
22}
23
24pub fn base64url_encode<T: AsRef<[u8]>>(bytes: T) -> String {
25    BASE64URL_NOPAD.encode(bytes.as_ref())
26}
27
28pub fn base64url_decode<T: AsRef<[u8]>>(bytes: T) -> Vec<u8> {
29    BASE64URL_NOPAD.decode(bytes.as_ref()).unwrap()
30}
31
32// Encodes a struct in base64url
33pub fn base64url_encode_serializable<T: Serialize>(value: T) -> String {
34    let bytes = serde_json::to_vec(&value).unwrap();
35    base64url_encode(bytes)
36}
37
38pub struct EncondingKey {
39    //TODO: family attribute implement something like this
40    //             ProofAlgorithm::EdDSA => AlgorithmFamily::Ed,
41    //             ProofAlgorithm::BBS_X (or BBS_BLS12381_SHA256, BBS_BLS12381_SHAKE256) => AlgorithmFamily::Bls12381
42}
43
44//TODO: implement From<Jwk> trait that transform a Jwk into and EncodingKey
45//es. if crv
46
47pub struct DecondingKey {}