Ejemplo n.º 1
0
func (self *Store) Op_hash(operation *operations.Hash) (ret bucket.BucketReturn) {

	opGet := operations.Get{
		BucketId: operation.BucketId,
		Key:      operation.Key,
	}
	ret = self.Op_get(&opGet)
	if !ret.GetCode().IsOk() {
		// Error
		return
	}
	if ret.GetCode() == retcode.OkNotFound {
		// Not found, so we cannot hash it
		return
	}

	// Ok, something we can hash
	returnGet := ret.(*operations.GetReturn)
	value := returnGet.Value

	hasher := hasher.NewHasher(value)

	hashreturn := new(operations.HashReturn)
	hashreturn.FirstElementSha256Hash = hasher.FirstElement()
	hashreturn.AllElementsSha256Hash = hasher.AllElements()
	hashreturn.Status = retcode.NewStatusOk()

	return hashreturn
}
Ejemplo n.º 2
0
func fillMissingHashesAccordingToConfig(returnConfig *operations.ReturnConfig,
	value types.Array,
	hashes *hashes.Hashes) {
	// Can only return hashes if value is available
	if returnConfig.HashReturn && value != nil {
		// Ok, need hashes
		if hashes.AllElementsSha256Hash == nil ||
			hashes.FirstElementSha256Hash == nil {
			// Ok, hash is missing
			hasher := hasher.NewHasher(value)
			hashes.FirstElementSha256Hash = hasher.FirstElement()
			hashes.AllElementsSha256Hash = hasher.AllElements()
		}
	}
}