Debian Codegraph @

internal/signinit/timestamper.go

raw symbols SCIP
1 // Copyright © SAS Institute Inc.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 package signinit
15
16 import (
17 "sync"
18
19 "github.com/sassoftware/relic/v7/cmdline/shared"
20 "github.com/sassoftware/relic/v7/lib/pkcs9"
21 "github.com/sassoftware/relic/v7/lib/pkcs9/tsclient"
22 )
23
24 var (
25 mu sync.Mutex
26 ts pkcs9.Timestamper
27 )
28
29 func GetTimestamper() (pkcs9.Timestamper, error) {
30 mu.Lock()
31 defer mu.Unlock()
32 var err error
33 if ts == nil {
34 ts, err = newTimestamper()
35 }
36 return ts, err
37 }
38
39 func newTimestamper() (timestamper pkcs9.Timestamper, err error) {
40 tsconf, err := shared.CurrentConfig.GetTimestampConfig()
41 if err != nil {
42 return nil, err
43 }
44 timestamper, err = tsclient.New(tsconf)
45 if err != nil {
46 return
47 }
48 return timestamper, nil
49 }