File: key_windows.go

package info (click to toggle)
golang-github-smallstep-crypto 0.57.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,284 kB
  • sloc: sh: 53; makefile: 36
file content (31 lines) | stat: -rw-r--r-- 709 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//go:build windows
// +build windows

package key

import (
	"fmt"
	"io"
)

func create(_ io.ReadWriteCloser, keyName string, config CreateConfig) ([]byte, error) {
	pcp, err := openPCP()
	if err != nil {
		return nil, fmt.Errorf("failed to open PCP: %w", err)
	}
	defer pcp.Close()

	_, pub, _, err := pcp.NewKey(keyName, &KeyConfig{Algorithm: Algorithm(config.Algorithm), Size: config.Size})
	if err != nil {
		return nil, fmt.Errorf("pcp failed to mint application key: %w", err)
	}

	out := serializedKey{
		Encoding:   keyEncodingOSManaged,
		TPMVersion: uint8(2), // hardcoded to not import github.com/google/go-attestation/attest
		Name:       keyName,
		Public:     pub,
	}

	return out.Serialize()
}