mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 18:15:42 +01:00
Split code to more files. Mainly move processor code to its own file.
This commit is contained in:
parent
b5c5d8db4b
commit
f2dd5a89a7
3 changed files with 453 additions and 421 deletions
46
cmd/csaf_checker/util.go
Normal file
46
cmd/csaf_checker/util.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// This file is Free Software under the MIT License
|
||||
// without warranty, see README.md and LICENSES/MIT.txt for details.
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2021 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de>
|
||||
// Software-Engineering: 2021 Intevation GmbH <https://intevation.de>
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/hex"
|
||||
"io"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var hexRe = regexp.MustCompile(`^([[:xdigit:]]+)`)
|
||||
|
||||
func hashFromReader(r io.Reader) ([]byte, error) {
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
if m := hexRe.FindStringSubmatch(scanner.Text()); m != nil {
|
||||
return hex.DecodeString(m[1])
|
||||
}
|
||||
}
|
||||
return nil, scanner.Err()
|
||||
}
|
||||
|
||||
func basePath(p string) (string, error) {
|
||||
u, err := url.Parse(p)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
ep := u.EscapedPath()
|
||||
if idx := strings.LastIndexByte(ep, '/'); idx != -1 {
|
||||
ep = ep[:idx]
|
||||
}
|
||||
user := u.User.String()
|
||||
if user != "" {
|
||||
user += "@"
|
||||
}
|
||||
return u.Scheme + "://" + user + u.Host + "/" + ep, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue