github.com/mre-fog/trillianxx@v1.1.2-0.20180615153820-ae375a99d36a/docs/storage/commit_log/signer/fakedb.go (about)

     1  // Copyright 2017 Google Inc. All Rights Reserved.
     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  
    15  package signer
    16  
    17  // FakeDatabase simulates a local database
    18  type FakeDatabase struct {
    19  	leaves []string
    20  	sth    STH
    21  }
    22  
    23  // Size returns the tree size of the local database
    24  func (f *FakeDatabase) Size() int {
    25  	return len(f.leaves)
    26  }
    27  
    28  // AddLeaves simulates adding leaves to the local database.  It returns
    29  // the STH in the database.
    30  func (f *FakeDatabase) AddLeaves(when int64, offset int, leaves []string) STH {
    31  	f.leaves = append(f.leaves, leaves...)
    32  	f.sth.TimeStamp = when
    33  	f.sth.Offset = offset
    34  	f.sth.TreeSize = f.Size()
    35  	return f.sth
    36  }