Beispiel #1
0
        /// <summary>
        /// Deserializes a Biscuit token from a byte array
        /// This checks the signature, but does not verify that the first key is the root key,
        /// to allow appending blocks without knowing about the root key.
        /// The root key check is performed in the verify method
        /// </summary>
        /// <param name="data"></param>
        /// <param name="symbols"></param>
        /// <returns></returns>
        static public Either <Error, Biscuit> FromBytesWithSymbols(byte[] data, SymbolTable symbols)
        {
            Either <Error, SerializedBiscuit> res = SerializedBiscuit.FromBytes(data);

            if (res.IsLeft)
            {
                Error e = res.Left;
                return(new Left(e));
            }

            SerializedBiscuit           ser     = res.Right;
            Either <FormatError, Block> authRes = Block.FromBytes(ser.authority);

            if (authRes.IsLeft)
            {
                Error e = authRes.Left;
                return(new Left(e));
            }
            Block authority = authRes.Right;

            List <Block> blocks = new List <Block>();

            foreach (byte[] bdata in ser.blocks)
            {
                Either <FormatError, Block> blockRes = Block.FromBytes(bdata);
                if (blockRes.IsLeft)
                {
                    return(blockRes.Left);
                }
                blocks.Add(blockRes.Right);
            }

            foreach (string s in authority.Symbols.Symbols)
            {
                symbols.Add(s);
            }

            foreach (Block b in blocks)
            {
                foreach (string s in b.Symbols.Symbols)
                {
                    symbols.Add(s);
                }
            }

            List <RevocationIdentifier> revocationIds = ser.RevocationIdentifiers();

            return(new Right(new Biscuit(authority, blocks, symbols, Option.Some(ser), revocationIds)));
        }