示例#1
0
        public static SafeGetResponse Call(ImmuService.ImmuServiceClient immuS, RootService rs, SafeGetOptions request)
        {
            var root  = rs.GetRoot();
            var index = new Immudb.Schema.Index
            {
                Index_ = root.Index
            };

            var protoReq = new SafeGetOptions(request)
            {
                RootIndex = index
            };

            var msg      = immuS.SafeGet(protoReq);
            var verified = Proofs.Verify(msg.Proof, ItemUtils.GetHash(msg.Item), root);

            if (verified)
            {
                var toCache = new Root
                {
                    Index = msg.Proof.At,
                    Root_ = msg.Proof.Root
                };

                try
                {
                    rs.SetRoot(toCache);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }

            var i = msg.Item;

            var timestampBytes = i.Value.Take(8).ToArray();

            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(timestampBytes);
            }

            return(new SafeGetResponse
            {
                Index = i.Index,
                Key = i.Key,
                Value = ByteString.CopyFrom(i.Value.Skip(8).ToArray()),
                Timestamp = BitConverter.ToInt64(timestampBytes),
                Verified = verified
            });
        }
示例#2
0
        public async Task <byte[]> SafeGetRawAsync(string key)
        {
            var root = this.getActiveDatabaseRoot();

            var request = new SafeGetOptions()
            {
                Key       = ByteString.CopyFromUtf8(key),
                RootIndex = new Index()
                {
                    Index_ = root.Index
                }
            };

            var result = await this.client.SafeGetAsync(request, this.getSecurityHeader());

            CryptoUtils.Verify(result.Proof, result.Item, root);

            this.rootHolder.SetRoot(this.activeDatabaseName, new Root()
            {
                Root_ = result.Proof.Root, Index = result.Proof.At
            });

            return(result.Item.Value.ToByteArray());
        }
示例#3
0
 public SafeGetResponse SafeGet(SafeGetOptions request)
 {
     return(Handler.SafeGet.Call(this.instance, this.rootService, request));
 }