func (dataVerifier *DataVerifier) VerifyDataSignature(data io.Reader, orgID string, objectType string, objectID string, destinationDataURI string) (bool, common.SyncServiceError) {
	if dataVerifier.writeThrough {
		return true, nil
	}
	if publicKeyBytes, err := base64.StdEncoding.DecodeString(dataVerifier.publicKey); err != nil {
		return false, &common.InternalError{Message: "PublicKey is not base64 encoded. Error: " + err.Error()}
	} else if signatureBytes, err := base64.StdEncoding.DecodeString(dataVerifier.signature); err != nil {
		return false, &common.InternalError{Message: "Signature is not base64 encoded. Error: " + err.Error()}
	} else {
		dr := io.TeeReader(data, dataVerifier.dataHash)
		if trace.IsLogging(logger.DEBUG) {
			trace.Debug("DataVerifier - In VerifyDataSignature, verifying and storing temp data for object %s %s\n", objectType, objectID)
		}
		if destinationDataURI != "" {
			if _, err := dataURI.StoreTempData(destinationDataURI, dr, 0); err != nil {
				return false, err
			}
		} else {
			if exists, err := Store.StoreObjectTempData(orgID, objectType, objectID, dr); err != nil || !exists {
				return false, err
			}
		}
		return dataVerifier.verifyHelper(publicKeyBytes, signatureBytes)
	}
}
VerifyDataSignature is to verify the data. This function will generate the tmp data in storage. Call RemoveTempData() after verification to remove the tmp data
package dataVerifier
import (
	"crypto"
	"crypto/rsa"
	"crypto/x509"
	"encoding/base64"
	"fmt"
	"hash"
	"io"
	"github.com/open-horizon/edge-sync-service/common"
	"github.com/open-horizon/edge-sync-service/core/dataURI"
	"github.com/open-horizon/edge-sync-service/core/storage"
	"github.com/open-horizon/edge-utilities/logger"
	"github.com/open-horizon/edge-utilities/logger/trace"
)
type DataVerifier struct {
	dataHash       hash.Hash
	cryptoHashType crypto.Hash
	publicKey      string
	signature      string
	writeThrough   bool
}
var Store storage.Storage
func NewDataVerifier(hashAlgorithm string, publicKey string, signature string) *DataVerifier {
	writeThrough := false
	var dataHash hash.Hash
	var cryptoHashType crypto.Hash
	var err error
	if !common.IsValidHashAlgorithm(hashAlgorithm) || publicKey == "" || signature == "" {
		writeThrough = true
	}
	if dataHash, cryptoHashType, err = common.GetHash(hashAlgorithm); err != nil {
		writeThrough = true
	}
	return &DataVerifier{
		dataHash:       dataHash,
		cryptoHashType: cryptoHashType,
		publicKey:      publicKey,
		signature:      signature,
		writeThrough:   writeThrough,
	}
}