validator.go 754 Bytes
Newer Older
lash's avatar
lash committed
1 2 3 4 5 6 7 8 9
// Copyright 2020 The Swarm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package soc

import (
	"github.com/ethersphere/bee/pkg/swarm"
)

10
var _ swarm.Validator = (*Validator)(nil)
lash's avatar
lash committed
11 12 13

// SocVaildator validates that the address of a given chunk
// is a single-owner chunk.
14
type Validator struct {
lash's avatar
lash committed
15 16
}

17
// NewValidator creates a new Validator.
18
func NewValidator() swarm.Validator {
19
	return &Validator{}
lash's avatar
lash committed
20 21 22
}

// Validate performs the validation check.
23
func (v *Validator) Validate(ch swarm.Chunk) (valid bool) {
lash's avatar
lash committed
24 25 26 27 28 29 30 31 32 33 34
	s, err := FromChunk(ch)
	if err != nil {
		return false
	}

	address, err := s.Address()
	if err != nil {
		return false
	}
	return ch.Address().Equal(address)
}