コード例 #1
0
        public static Either <Error, Biscuit> FromSealed(byte[] data, byte[] secret)
        {
            //FIXME: needs a version of from_sealed with custom symbol table support
            SymbolTable symbols = DefaultSymbolTable();

            Either <Error, SealedBiscuit> res = SealedBiscuit.FromBytes(data, secret);

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

            SealedBiscuit 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> revocation_ids = ser.RevocationIdentifiers();

            return(new Biscuit(authority, blocks, symbols, Option <SerializedBiscuit> .None(), revocation_ids));
        }
コード例 #2
0
        public Either <FormatError, byte[]> Seal(byte[] secret)
        {
            Either <FormatError, SealedBiscuit> res = SealedBiscuit.Make(Authority, Blocks, secret);

            if (res.IsLeft)
            {
                return(res.Left);
            }

            SealedBiscuit b = res.Right;

            return(b.Serialize());
        }