• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / iot-manager / 1401702106

05 Aug 2024 08:32PM UTC coverage: 87.577%. Remained the same
1401702106

push

gitlab-ci

web-flow
Merge pull request #295 from mendersoftware/dependabot/docker/docker-dependencies-03b04ac819

chore: bump golang from 1.22.4-alpine3.19 to 1.22.5-alpine3.19 in the docker-dependencies group

3264 of 3727 relevant lines covered (87.58%)

11.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/crypto/string.go
1
// Copyright 2022 Northern.tech AS
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 crypto
16

17
import (
18
        "github.com/pkg/errors"
19
        "go.mongodb.org/mongo-driver/bson"
20
)
21

22
type String string
23

24
type stringBSON struct {
25
        Algorithm string `bson:"algorithm"`
26
        KeyID     string `bson:"keyID,omitempty"`
27
        Data      []byte `bson:"data"`
28
}
29

30
const (
31
        algorithmAES_256_CFB_HMAC_SHA512 = "AES_256_CFB_HMAC_SHA512"
32
        omitted                          = "<omitted>"
33
)
34

35
var (
36
        ErrUnknownAlgorithm = errors.New("unknown algorithm")
37
)
38

39
func (c *String) MarshalText() ([]byte, error) {
1✔
40
        return []byte(omitted), nil
1✔
41
}
1✔
42

43
func (s *String) MarshalBSON() ([]byte, error) {
10✔
44
        out, err := AESEncrypt(string(*s))
10✔
45
        if err != nil {
11✔
46
                return nil, err
1✔
47
        }
1✔
48
        return bson.Marshal(&stringBSON{
9✔
49
                Algorithm: algorithmAES_256_CFB_HMAC_SHA512,
9✔
50
                Data:      out,
9✔
51
        })
9✔
52
}
53

54
func (s *String) UnmarshalBSON(data []byte) error {
15✔
55
        out := &stringBSON{}
15✔
56
        err := bson.Unmarshal(data, out)
15✔
57
        if err != nil {
16✔
58
                return err
1✔
59
        } else if out.Algorithm != algorithmAES_256_CFB_HMAC_SHA512 {
16✔
60
                return ErrUnknownAlgorithm
1✔
61
        }
1✔
62
        value, err := AESDecrypt(out.Data)
13✔
63
        if err == nil {
26✔
64
                *s = String(value)
13✔
65
        }
13✔
66
        return err
13✔
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc