xref: /aosp_15_r20/external/tink/go/signature/proto.go (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1// Copyright 2019 Google LLC
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////////////////////////////////////////////////////////////////////////////////
16
17package signature
18
19import (
20	commonpb "github.com/google/tink/go/proto/common_go_proto"
21	ecdsapb "github.com/google/tink/go/proto/ecdsa_go_proto"
22)
23
24// getECDSAParamNames returns the string representations of each parameter in
25// the given ECDSAParams.
26func getECDSAParamNames(params *ecdsapb.EcdsaParams) (string, string, string) {
27	hashName := commonpb.HashType_name[int32(params.HashType)]
28	curveName := commonpb.EllipticCurveType_name[int32(params.Curve)]
29	encodingName := ecdsapb.EcdsaSignatureEncoding_name[int32(params.Encoding)]
30	return hashName, curveName, encodingName
31}
32
33// newECDSAPrivateKey creates a ECDSAPrivateKey with the specified paramaters.
34func newECDSAPrivateKey(version uint32, publicKey *ecdsapb.EcdsaPublicKey, keyValue []byte) *ecdsapb.EcdsaPrivateKey {
35	return &ecdsapb.EcdsaPrivateKey{
36		Version:   version,
37		PublicKey: publicKey,
38		KeyValue:  keyValue,
39	}
40}
41
42// newECDSAPublicKey creates a ECDSAPublicKey with the specified paramaters.
43func newECDSAPublicKey(version uint32, params *ecdsapb.EcdsaParams, x, y []byte) *ecdsapb.EcdsaPublicKey {
44	return &ecdsapb.EcdsaPublicKey{
45		Version: version,
46		Params:  params,
47		X:       x,
48		Y:       y,
49	}
50}
51