...

Source file src/cuelang.org/go/pkg/crypto/ed25519/ed25519.go

Documentation: cuelang.org/go/pkg/crypto/ed25519

     1  // Copyright 2021 The CUE Authors
     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 ed25519
    16  
    17  import (
    18  	"crypto/ed25519"
    19  
    20  	"cuelang.org/go/cue/errors"
    21  	"cuelang.org/go/cue/token"
    22  )
    23  
    24  const (
    25  	// PublicKeySize is the size of a public key in bytes.
    26  	PublicKeySize = 32
    27  )
    28  
    29  // Valid verifies the provided signature of the message using the public key.
    30  // An error is returned if and only if an invalid public key is provided.
    31  func Valid(publicKey, message, signature []byte) (bool, error) {
    32  	if size := len(publicKey); size != PublicKeySize {
    33  		return false, errors.Newf(token.NoPos, "ed25519: publicKey must be 32 bytes")
    34  	}
    35  	return ed25519.Verify(publicKey, message, signature), nil
    36  }
    37  

View as plain text