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

mendersoftware / openssl / 1676124181

18 Feb 2025 09:25AM UTC coverage: 51.177% (-1.0%) from 52.175%
1676124181

push

gitlab-ci

web-flow
Merge pull request #39 from mendersoftware/QA-814-add-dependabot

QA-814: Add dependabot configuration

1435 of 2804 relevant lines covered (51.18%)

2313.66 hits per line

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

0.0
/md4.go
1
// Copyright (C) 2017. See 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 openssl
16

17
// #include "shim.h"
18
import "C"
19

20
import (
21
        "errors"
22
        "runtime"
23
        "unsafe"
24
)
25

26
type MD4Hash struct {
27
        ctx    *C.EVP_MD_CTX
28
        engine *Engine
29
}
30

31
func NewMD4Hash() (*MD4Hash, error) { return NewMD4HashWithEngine(nil) }
×
32

33
func NewMD4HashWithEngine(e *Engine) (*MD4Hash, error) {
×
34
        hash := &MD4Hash{engine: e}
×
35
        hash.ctx = C.X_EVP_MD_CTX_new()
×
36
        if hash.ctx == nil {
×
37
                return nil, errors.New("openssl: md4: unable to allocate ctx")
×
38
        }
×
39
        runtime.SetFinalizer(hash, func(hash *MD4Hash) { hash.Close() })
×
40
        if err := hash.Reset(); err != nil {
×
41
                return nil, err
×
42
        }
×
43
        return hash, nil
×
44
}
45

46
func (s *MD4Hash) Close() {
×
47
        if s.ctx != nil {
×
48
                C.X_EVP_MD_CTX_free(s.ctx)
×
49
                s.ctx = nil
×
50
        }
×
51
}
52

53
func (s *MD4Hash) Reset() error {
×
54
        if 1 != C.X_EVP_DigestInit_ex(s.ctx, C.X_EVP_md4(), engineRef(s.engine)) {
×
55
                return errors.New("openssl: md4: cannot init digest ctx")
×
56
        }
×
57
        runtime.KeepAlive(s)
×
58
        return nil
×
59
}
60

61
func (s *MD4Hash) Write(p []byte) (n int, err error) {
×
62
        if len(p) == 0 {
×
63
                return 0, nil
×
64
        }
×
65
        if 1 != C.X_EVP_DigestUpdate(s.ctx, unsafe.Pointer(&p[0]),
×
66
                C.size_t(len(p))) {
×
67
                return 0, errors.New("openssl: md4: cannot update digest")
×
68
        }
×
69
        runtime.KeepAlive(s)
×
70
        return len(p), nil
×
71
}
72

73
func (s *MD4Hash) Sum() (result [16]byte, err error) {
×
74
        if 1 != C.X_EVP_DigestFinal_ex(s.ctx,
×
75
                (*C.uchar)(unsafe.Pointer(&result[0])), nil) {
×
76
                return result, errors.New("openssl: md4: cannot finalize ctx")
×
77
        }
×
78
        return result, s.Reset()
×
79
}
80

81
func MD4(data []byte) (result [16]byte, err error) {
×
82
        hash, err := NewMD4Hash()
×
83
        if err != nil {
×
84
                return result, err
×
85
        }
×
86
        defer hash.Close()
×
87
        if _, err := hash.Write(data); err != nil {
×
88
                return result, err
×
89
        }
×
90
        return hash.Sum()
×
91
}
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