diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 379cba3..fdd8227 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,13 +41,13 @@ jobs: - uses: crazy-max/ghaction-upx@db8cc9515a4a7ea1b312cb82fbeae6d716daf777 # v3.2.0 with: install-only: true - - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 + - uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 with: go-version-file: go.mod check-latest: true cache-dependency-path: "**/*.sum" - - uses: sigstore/cosign-installer@d58896d6a1865668819e1d91763c7751a165e159 # v3.9.2 - - uses: anchore/sbom-action/download-syft@7b36ad622f042cab6f59a75c2ac24ccb256e9b45 # v0.20.4 + - uses: sigstore/cosign-installer@d7543c93d881b35a8faa02e8e3605f69b7a1ce62 # v3.10.0 + - uses: anchore/sbom-action/download-syft@f8bdd1d8ac5e901a77a92f111440fdb1b593736b # v0.20.6 - name: setup-tparse run: go install github.com/mfridman/tparse@latest - name: Install dependencies @@ -63,7 +63,7 @@ jobs: run: task test - name: Run go tests with coverage for github actions run: ./scripts/test.sh - - uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3 + - uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1 with: file: ./coverage.txt - run: ./papercrypt version diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index cfb9fd4..a88eda6 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -37,7 +37,7 @@ jobs: - name: Checkout repository uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 + - uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 with: go-version-file: go.mod check-latest: true diff --git a/.github/workflows/depsreview.yaml b/.github/workflows/depsreview.yaml index e5a09fa..d9dc3be 100644 --- a/.github/workflows/depsreview.yaml +++ b/.github/workflows/depsreview.yaml @@ -10,6 +10,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - uses: actions/dependency-review-action@da24556b548a50705dd671f47852072ea4c105d9 # v4.7.1 + - uses: actions/dependency-review-action@56339e523c0409420f6c2c9a2f4292bbb3c07dd3 # v4.8.0 with: config-file: "./.github/dependency-review-config.yml" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 08a977e..f2b799c 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 + - uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 with: go-version: stable cache: false diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ab6f804..c8d828d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 + uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 with: go-version-file: go.mod check-latest: true @@ -31,7 +31,7 @@ jobs: repo-token: ${{ secrets.GITHUB_TOKEN }} - name: Install GoReleaser - uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # v6.3.0 + uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0 with: install-only: true @@ -56,7 +56,7 @@ jobs: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 + uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 with: go-version-file: go.mod check-latest: true @@ -85,7 +85,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 + - uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 with: go-version: stable cache: false @@ -114,7 +114,7 @@ jobs: run: git fetch --force --tags - name: Set up Go - uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 + uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0 with: go-version-file: go.mod check-latest: true @@ -125,11 +125,11 @@ jobs: run: echo "GOVERSION=$(go version)" >> $GITHUB_OUTPUT - name: Set up Node - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 + uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0 with: node-version: 22 - - uses: sigstore/cosign-installer@d58896d6a1865668819e1d91763c7751a165e159 # v3.9.2 + - uses: sigstore/cosign-installer@d7543c93d881b35a8faa02e8e3605f69b7a1ce62 # v3.10.0 - name: Confirm cosign installation run: cosign version @@ -150,11 +150,11 @@ jobs: repo-token: ${{ secrets.GITHUB_TOKEN }} - name: Install GoReleaser - uses: goreleaser/goreleaser-action@9c156ee8a17a598857849441385a2041ef570552 # v6.3.0 + uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0 with: install-only: true - - uses: anchore/sbom-action/download-syft@7b36ad622f042cab6f59a75c2ac24ccb256e9b45 # v0.20.4 + - uses: anchore/sbom-action/download-syft@f8bdd1d8ac5e901a77a92f111440fdb1b593736b # v0.20.6 - name: Set up QEMU uses: docker/setup-qemu-action@29109295f81e9208d7d86ff1c6c12d2833863392 # v3.6.0 diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 3c26361..ef3313c 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -122,8 +122,6 @@ docker_signs: homebrew_casks: - name: papercrypt - conflicts: - - formula: papercrypt # alternative_names: # - papercrypt@{{ .Version }} # - papercrypt@{{ .Major }}.{{ .Minor }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 739c9f1..e2890cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## [2.0.3](https://github.com/TMUniversal/papercrypt/compare/v2.0.2...v2.0.3) (2025-09-28) + + +### Bug Fixes + +* **deps:** update module github.com/caarlos0/go-version to v0.2.2 ([7ae85c4](https://github.com/TMUniversal/papercrypt/commit/7ae85c4e170a83b9bbcb140218637d257e13b0ef)) +* **deps:** update module github.com/muesli/mango-cobra to v1.3.0 ([6ed0cdf](https://github.com/TMUniversal/papercrypt/commit/6ed0cdfe3bc25e22be9e92a6d56e9b9c4f77b643)) +* **deps:** update module github.com/spf13/cobra to v1.10.1 ([48d0a3f](https://github.com/TMUniversal/papercrypt/commit/48d0a3f772c384cab8689782605e1bc59467503a)) +* **deps:** update module github.com/stretchr/testify to v1.11.1 ([f9361d9](https://github.com/TMUniversal/papercrypt/commit/f9361d941dbd9ea205246fec2b1589d30dfa2f9c)) +* **deps:** update module golang.org/x/term to v0.35.0 ([00a4339](https://github.com/TMUniversal/papercrypt/commit/00a4339d3d3c23d4d7ad81748cc7e95c773991c4)) + ## [2.0.2](https://github.com/TMUniversal/papercrypt/compare/v2.0.1...v2.0.2) (2025-08-12) diff --git a/THIRD_PARTY.md b/THIRD_PARTY.md index ecbb2b5..403c034 100644 --- a/THIRD_PARTY.md +++ b/THIRD_PARTY.md @@ -102,6 +102,37 @@ IN THE SOFTWARE. ``` +## github.com/ProtonMail/gopenpgp/v3 + +* Name: github.com/ProtonMail/gopenpgp/v3 +* Version: v3.3.0 +* License: [MIT](https://github.com/ProtonMail/gopenpgp/blob/v3.3.0/LICENSE) + +```md +(The MIT License) + +Copyright (c) 2019 Proton Technologies AG + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to +deal in the Software without restriction, including without limitation the +rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +sell copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. + +``` + ## github.com/aymanbagabas/go-osc52/v2 * Name: github.com/aymanbagabas/go-osc52/v2 @@ -167,23 +198,31 @@ SOFTWARE. ## github.com/caarlos0/go-version * Name: github.com/caarlos0/go-version -* Version: v0.2.1 -* License: [Apache-2.0](https://github.com/caarlos0/go-version/blob/v0.2.1/LICENSE.md) +* Version: v0.2.2 +* License: [MIT](https://github.com/caarlos0/go-version/blob/v0.2.2/LICENSE.md) ```md -Copyright 2022 The Kubernetes Authors. +The MIT License (MIT) -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at +Copyright (c) 2025 Carlos Alexandro Becker - http://www.apache.org/licenses/LICENSE-2.0 +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. ``` @@ -277,8 +316,8 @@ SOFTWARE. ## github.com/charmbracelet/colorprofile * Name: github.com/charmbracelet/colorprofile -* Version: v0.3.1 -* License: [MIT](https://github.com/charmbracelet/colorprofile/blob/v0.3.1/LICENSE) +* Version: v0.3.2 +* License: [MIT](https://github.com/charmbracelet/colorprofile/blob/v0.3.2/LICENSE) ```md MIT License @@ -593,8 +632,8 @@ SOFTWARE. ## github.com/lucasb-eyer/go-colorful * Name: github.com/lucasb-eyer/go-colorful -* Version: v1.2.0 -* License: [MIT](https://github.com/lucasb-eyer/go-colorful/blob/v1.2.0/LICENSE) +* Version: v1.3.0 +* License: [MIT](https://github.com/lucasb-eyer/go-colorful/blob/v1.3.0/LICENSE) ```md Copyright (c) 2013 Lucas Beyer @@ -908,8 +947,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI ## github.com/mattn/go-runewidth * Name: github.com/mattn/go-runewidth -* Version: v0.0.16 -* License: [MIT](https://github.com/mattn/go-runewidth/blob/v0.0.16/LICENSE) +* Version: v0.0.17 +* License: [MIT](https://github.com/mattn/go-runewidth/blob/v0.0.17/LICENSE) ```md The MIT License (MIT) @@ -1001,8 +1040,8 @@ SOFTWARE. ## github.com/muesli/mango-cobra * Name: github.com/muesli/mango-cobra -* Version: v1.2.0 -* License: [MIT](https://github.com/muesli/mango-cobra/blob/v1.2.0/LICENSE) +* Version: v1.3.0 +* License: [MIT](https://github.com/muesli/mango-cobra/blob/v1.3.0/LICENSE) ```md MIT License @@ -1032,8 +1071,8 @@ SOFTWARE. ## github.com/muesli/mango-pflag * Name: github.com/muesli/mango-pflag -* Version: v0.1.0 -* License: [MIT](https://github.com/muesli/mango-pflag/blob/v0.1.0/LICENSE) +* Version: v0.2.0 +* License: [MIT](https://github.com/muesli/mango-pflag/blob/v0.2.0/LICENSE) ```md MIT License @@ -1189,8 +1228,8 @@ SOFTWARE. ## github.com/spf13/cobra * Name: github.com/spf13/cobra -* Version: v1.9.1 -* License: [Apache-2.0](https://github.com/spf13/cobra/blob/v1.9.1/LICENSE.txt) +* Version: v1.10.1 +* License: [Apache-2.0](https://github.com/spf13/cobra/blob/v1.10.1/LICENSE.txt) ```md Apache License @@ -1373,8 +1412,8 @@ SOFTWARE. ## github.com/spf13/pflag * Name: github.com/spf13/pflag -* Version: v1.0.7 -* License: [BSD-3-Clause](https://github.com/spf13/pflag/blob/v1.0.7/LICENSE) +* Version: v1.0.10 +* License: [BSD-3-Clause](https://github.com/spf13/pflag/blob/v1.0.10/LICENSE) ```md Copyright (c) 2012 Alex Ogier. All rights reserved. @@ -1442,8 +1481,8 @@ SOFTWARE. ## golang.org/x/crypto * Name: golang.org/x/crypto -* Version: v0.41.0 -* License: [BSD-3-Clause](https://cs.opensource.google/go/x/crypto/+/v0.41.0:LICENSE) +* Version: v0.42.0 +* License: [BSD-3-Clause](https://cs.opensource.google/go/x/crypto/+/v0.42.0:LICENSE) ```md Copyright 2009 The Go Authors. @@ -1479,8 +1518,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## golang.org/x/sys * Name: golang.org/x/sys -* Version: v0.35.0 -* License: [BSD-3-Clause](https://cs.opensource.google/go/x/sys/+/v0.35.0:LICENSE) +* Version: v0.36.0 +* License: [BSD-3-Clause](https://cs.opensource.google/go/x/sys/+/v0.36.0:LICENSE) ```md Copyright 2009 The Go Authors. @@ -1516,8 +1555,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## golang.org/x/term * Name: golang.org/x/term -* Version: v0.34.0 -* License: [BSD-3-Clause](https://cs.opensource.google/go/x/term/+/v0.34.0:LICENSE) +* Version: v0.35.0 +* License: [BSD-3-Clause](https://cs.opensource.google/go/x/term/+/v0.35.0:LICENSE) ```md Copyright 2009 The Go Authors. @@ -1553,8 +1592,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ## golang.org/x/text * Name: golang.org/x/text -* Version: v0.28.0 -* License: [BSD-3-Clause](https://cs.opensource.google/go/x/text/+/v0.28.0:LICENSE) +* Version: v0.29.0 +* License: [BSD-3-Clause](https://cs.opensource.google/go/x/text/+/v0.29.0:LICENSE) ```md Copyright 2009 The Go Authors. diff --git a/cmd/decode_test.go b/cmd/decode_test.go index 72fe9bc..21c0a79 100644 --- a/cmd/decode_test.go +++ b/cmd/decode_test.go @@ -25,6 +25,7 @@ import ( "testing" "github.com/caarlos0/log" + "github.com/stretchr/testify/assert" ) const input = `{ @@ -148,18 +149,21 @@ func TestDecodeV1(t *testing.T) { t.Fatal(err) } - if err := cmd.Execute(); err != nil { - t.Fatal(err) - } + assert.NoError(t, cmd.Execute(), "command execution failed") out, err := os.ReadFile(outPath) if err != nil { t.Fatal(err) } - if string(out) != input { - t.Fatalf("Expected %s, got %s", input, string(out)) - } + assert.Equal( + t, + input, + string(out), + "expected output to match input. Expected: %s, got: %s", + input, + string(out), + ) } func TestDecodeV2(t *testing.T) { @@ -176,18 +180,21 @@ func TestDecodeV2(t *testing.T) { t.Fatal(err) } - if err := cmd.Execute(); err != nil { - t.Fatal(err) - } + assert.NoError(t, cmd.Execute(), "command execution failed") out, err := os.ReadFile(outPath) if err != nil { t.Fatal(err) } - if string(out) != input { - t.Fatalf("Expected %s, got %s", input, string(out)) - } + assert.Equal( + t, + input, + string(out), + "expected output to match input. Expected: %s, got: %s", + input, + string(out), + ) } func TestDecodeV2Raw(t *testing.T) { @@ -204,16 +211,19 @@ func TestDecodeV2Raw(t *testing.T) { t.Fatal(err) } - if err := cmd.Execute(); err != nil { - t.Fatal(err) - } + assert.NoError(t, cmd.Execute(), "command execution failed") out, err := os.ReadFile(outPath) if err != nil { t.Fatal(err) } - if string(out) != input { - t.Fatalf("Expected %s, got %s", input, string(out)) - } + assert.Equal( + t, + input, + string(out), + "expected output to match input. Expected: %s, got: %s", + input, + string(out), + ) } diff --git a/cmd/generate.go b/cmd/generate.go index 349ed77..463d53d 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -27,7 +27,7 @@ import ( "os" "time" - "github.com/ProtonMail/gopenpgp/v2/crypto" + "github.com/ProtonMail/gopenpgp/v3/crypto" "github.com/caarlos0/log" "github.com/spf13/cobra" "github.com/tmuniversal/papercrypt/v2/internal" @@ -156,7 +156,7 @@ encrypted data.`, compressedData.Reset() gzipWriter.Reset(compressedData) - _, err = gzipWriter.Write(encryptedSecretContents.GetBinary()) + _, err = gzipWriter.Write(encryptedSecretContents.Bytes()) if err != nil { return errors.Join(errors.New("error writing to gzip writer"), err) } @@ -201,14 +201,19 @@ encrypted data.`, } func encrypt(passphrase []byte, data []byte) (*crypto.PGPMessage, error) { - message := crypto.NewPlainMessage(data) + pgp := crypto.PGP() - encrypted, err := crypto.EncryptMessageWithPassword(message, passphrase) + encHandle, err := pgp.Encryption().Password(passphrase).New() if err != nil { - return nil, errors.Join(errors.New("error encrypting message"), err) + return nil, errors.Join(errors.New("error creating encryption handle"), err) } - return encrypted, nil + pgpMessage, err := encHandle.Encrypt(data) + if err != nil { + return nil, errors.Join(errors.New("error encrypting data"), err) + } + + return pgpMessage, nil } func init() { diff --git a/cmd/scan_code.go b/cmd/scan_code.go index c3a6863..8b302d8 100644 --- a/cmd/scan_code.go +++ b/cmd/scan_code.go @@ -32,6 +32,7 @@ import ( "github.com/makiuchi-d/gozxing/aztec" "github.com/makiuchi-d/gozxing/qrcode" "github.com/spf13/cobra" + pcv1 "github.com/tmuniversal/papercrypt/internal" "github.com/tmuniversal/papercrypt/v2/internal" ) @@ -80,12 +81,6 @@ The resulting JSON data can be read by this command, by supplying the --json fla if err != nil { return err } - defer func(inFile *os.File) { - err := internal.CloseFileIfNotStd(inFile) - if err != nil { - log.WithError(err).Warn("error closing input file") - } - }(inFile) var data []byte @@ -100,10 +95,6 @@ The resulting JSON data can be read by this command, by supplying the --json fla return errors.Join(errors.New("error decoding image"), err) } - if err := inFile.Close(); err != nil { - return errors.Join(errors.New("error closing input file"), err) - } - bmp, err := gozxing.NewBinaryBitmapFromImage(img) if err != nil { return errors.Join(errors.New("error creating binary bitmap"), err) @@ -126,6 +117,10 @@ The resulting JSON data can be read by this command, by supplying the --json fla data = []byte(result.GetText()) } + if err := internal.CloseFileIfNotStd(inFile); err != nil { + return errors.Join(errors.New("error closing input file"), err) + } + // 2. Open output file outFile, err := internal.GetFileHandleCarefully(outFileName, overrideOutFile) if err != nil { @@ -173,27 +168,33 @@ The resulting JSON data can be read by this command, by supplying the --json fla switch paperCryptMajorVersion { case internal.PaperCryptContainerVersionMajor1: - pc := internal.PaperCryptV1{} + pc := pcv1.PaperCrypt{} // Use the v1 package for PaperCrypt v1, as we do not need to have the serialization code here err = json.Unmarshal(data, &pc) if err != nil { - return errors.Join(errors.New("error deserializing data"), err) + return errors.Join( + errors.New("error deserializing json data as PaperCrypt v1"), + err, + ) } output, err = pc.GetText(false) if err != nil { - return errors.Join(errors.New("error deserializing data"), err) + return errors.Join(errors.New("error reserializing data as PaperCrypt text"), err) } case internal.PaperCryptContainerVersionDevel, internal.PaperCryptContainerVersionMajor2: pc := internal.PaperCrypt{} err = json.Unmarshal(data, &pc) if err != nil { - return errors.Join(errors.New("error deserializing data"), err) + return errors.Join( + errors.New("error deserializing json data as PaperCrypt v2"), + err, + ) } output, err = pc.GetText(false) if err != nil { - return errors.Join(errors.New("error deserializing data"), err) + return errors.Join(errors.New("error reserializing data as PaperCrypt text"), err) } default: return errors.New("unknown version") diff --git a/go.mod b/go.mod index f2585ba..cedcfe0 100644 --- a/go.mod +++ b/go.mod @@ -1,49 +1,55 @@ module github.com/tmuniversal/papercrypt/v2 -go 1.24.1 +go 1.24.6 require ( - github.com/ProtonMail/gopenpgp/v2 v2.9.0 + github.com/ProtonMail/gopenpgp/v3 v3.3.0 github.com/boombuler/barcode v1.1.0 - github.com/caarlos0/go-version v0.2.1 + github.com/caarlos0/go-version v0.2.2 github.com/caarlos0/log v0.5.1 github.com/ccoveille/go-safecast v1.6.1 github.com/charmbracelet/lipgloss v1.1.0 github.com/jung-kurt/gofpdf/v2 v2.17.3 github.com/makiuchi-d/gozxing v0.1.1 github.com/manifoldco/promptui v0.9.0 - github.com/muesli/mango-cobra v1.2.0 + github.com/muesli/mango-cobra v1.3.0 github.com/muesli/roff v0.1.0 github.com/muesli/termenv v0.16.0 - github.com/spf13/cobra v1.9.1 - golang.org/x/term v0.34.0 + github.com/spf13/cobra v1.10.1 + github.com/stretchr/testify v1.11.1 + github.com/tmuniversal/papercrypt v1.3.0 + golang.org/x/term v0.35.0 ) require ( github.com/ProtonMail/go-crypto v1.3.0 // indirect github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f // indirect + github.com/ProtonMail/gopenpgp/v2 v2.9.0 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect - github.com/charmbracelet/colorprofile v0.3.1 // indirect + github.com/charmbracelet/colorprofile v0.3.2 // indirect github.com/charmbracelet/lipgloss/v2 v2.0.0-beta1 // indirect github.com/charmbracelet/x/ansi v0.10.1 // indirect github.com/charmbracelet/x/cellbuf v0.0.13 // indirect github.com/charmbracelet/x/term v0.2.1 // indirect github.com/chzyer/readline v1.5.1 // indirect github.com/cloudflare/circl v1.6.1 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/lucasb-eyer/go-colorful v1.2.0 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/lucasb-eyer/go-colorful v1.3.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mattn/go-runewidth v0.0.16 // indirect + github.com/mattn/go-runewidth v0.0.17 // indirect github.com/muesli/cancelreader v0.2.2 // indirect github.com/muesli/mango v0.2.0 // indirect - github.com/muesli/mango-pflag v0.1.0 // indirect + github.com/muesli/mango-pflag v0.2.0 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect - github.com/spf13/pflag v1.0.7 // indirect - github.com/stretchr/testify v1.7.1 // indirect + github.com/spf13/pflag v1.0.10 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect - golang.org/x/crypto v0.41.0 // indirect - golang.org/x/sys v0.35.0 // indirect - golang.org/x/text v0.28.0 // indirect + golang.org/x/crypto v0.42.0 // indirect + golang.org/x/sys v0.36.0 // indirect + golang.org/x/text v0.29.0 // indirect golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index dd883c0..e6454b9 100644 --- a/go.sum +++ b/go.sum @@ -4,18 +4,20 @@ github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f h1:tCbYj7/299ek github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f/go.mod h1:gcr0kNtGBqin9zDW9GOHcVntrwnjrK+qdJ06mWYBybw= github.com/ProtonMail/gopenpgp/v2 v2.9.0 h1:ruLzBmwe4dR1hdnrsEJ/S7psSBmV15gFttFUPP/+/kE= github.com/ProtonMail/gopenpgp/v2 v2.9.0/go.mod h1:IldDyh9Hv1ZCCYatTuuEt1XZJ0OPjxLpTarDfglih7s= +github.com/ProtonMail/gopenpgp/v3 v3.3.0 h1:N6rHCH5PWwB6zSRMgRj1EbAMQHUAAHxH3Oo4KibsPwY= +github.com/ProtonMail/gopenpgp/v3 v3.3.0/go.mod h1:J+iNPt0/5EO9wRt7Eit9dRUlzyu3hiGX3zId6iuaKOk= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/boombuler/barcode v1.1.0 h1:ChaYjBR63fr4LFyGn8E8nt7dBSt3MiU3zMOZqFvVkHo= github.com/boombuler/barcode v1.1.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= -github.com/caarlos0/go-version v0.2.1 h1:bJY5WRvs2RXErLKBELd1WR0U72whX8ELbKg0WtQ9/7A= -github.com/caarlos0/go-version v0.2.1/go.mod h1:X+rI5VAtJDpcjCjeEIXpxGa5+rTcgur1FK66wS0/944= +github.com/caarlos0/go-version v0.2.2 h1:5r+nlrg4H2wOVwWjqRqRRIRbZ7ytRmjC9xoMIP0a5kQ= +github.com/caarlos0/go-version v0.2.2/go.mod h1:X+rI5VAtJDpcjCjeEIXpxGa5+rTcgur1FK66wS0/944= github.com/caarlos0/log v0.5.1 h1:uB1jhC/+HimtyyL7pxidkUWO4raKmidVuXifC4uqMf8= github.com/caarlos0/log v0.5.1/go.mod h1:37k7VCogxsMsgpIQaca5g9eXFFrLJ5LGgA4Ng/xN85o= github.com/ccoveille/go-safecast v1.6.1 h1:Nb9WMDR8PqhnKCVs2sCB+OqhohwO5qaXtCviZkIff5Q= github.com/ccoveille/go-safecast v1.6.1/go.mod h1:QqwNjxQ7DAqY0C721OIO9InMk9zCwcsO7tnRuHytad8= -github.com/charmbracelet/colorprofile v0.3.1 h1:k8dTHMd7fgw4bnFd7jXTLZrSU/CQrKnL3m+AxCzDz40= -github.com/charmbracelet/colorprofile v0.3.1/go.mod h1:/GkGusxNs8VB/RSOh3fu0TJmQ4ICMMPApIIVn0KszZ0= +github.com/charmbracelet/colorprofile v0.3.2 h1:9J27WdztfJQVAQKX2WOlSSRB+5gaKqqITmrvb1uTIiI= +github.com/charmbracelet/colorprofile v0.3.2/go.mod h1:mTD5XzNeWHj8oqHb+S1bssQb7vIHbepiebQ2kPKVKbI= github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY= github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30= github.com/charmbracelet/lipgloss/v2 v2.0.0-beta1 h1:SOylT6+BQzPHEjn15TIzawBPVD0QmhKXbcb3jY0ZIKU= @@ -38,30 +40,35 @@ github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38 github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0= github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/jung-kurt/gofpdf/v2 v2.17.3 h1:otZXZby2gXJ7uU6pzprXHq/R57lsHLi0WtH79VabWxY= github.com/jung-kurt/gofpdf/v2 v2.17.3/go.mod h1:Qx8ZNg4cNsO5i6uLDiBngnm+ii/FjtAqjRNO6drsoYU= -github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= -github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag= +github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/makiuchi-d/gozxing v0.1.1 h1:xxqijhoedi+/lZlhINteGbywIrewVdVv2wl9r5O9S1I= github.com/makiuchi-d/gozxing v0.1.1/go.mod h1:eRIHbOjX7QWxLIDJoQuMLhuXg9LAuw6znsUtRkNw9DU= github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA= github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= -github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-runewidth v0.0.17 h1:78v8ZlW0bP43XfmAfPsdXcoNCelfMHsDmd/pkENfrjQ= +github.com/mattn/go-runewidth v0.0.17/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= github.com/muesli/mango v0.2.0 h1:iNNc0c5VLQ6fsMgAqGQofByNUBH2Q2nEbD6TaI+5yyQ= github.com/muesli/mango v0.2.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4= -github.com/muesli/mango-cobra v1.2.0 h1:DQvjzAM0PMZr85Iv9LIMaYISpTOliMEg+uMFtNbYvWg= -github.com/muesli/mango-cobra v1.2.0/go.mod h1:vMJL54QytZAJhCT13LPVDfkvCUJ5/4jNUKF/8NC2UjA= -github.com/muesli/mango-pflag v0.1.0 h1:UADqbYgpUyRoBja3g6LUL+3LErjpsOwaC9ywvBWe7Sg= -github.com/muesli/mango-pflag v0.1.0/go.mod h1:YEQomTxaCUp8PrbhFh10UfbhbQrM/xJ4i2PB8VTLLW0= +github.com/muesli/mango-cobra v1.3.0 h1:vQy5GvPg3ndOSpduxutqFoINhWk3vD5K2dXo5E8pqec= +github.com/muesli/mango-cobra v1.3.0/go.mod h1:Cj1ZrBu3806Qw7UjxnAUgE+7tllUBj1NCLQDwwGx19E= +github.com/muesli/mango-pflag v0.2.0 h1:QViokgKDZQCzKhYe1zH8D+UlPJzBSGoP9yx0hBG0t5k= +github.com/muesli/mango-pflag v0.2.0/go.mod h1:X9LT1p/pbGA1wjvEbtwnixujKErkP0jVmrxwrw3fL0Y= github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8= github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig= github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= @@ -74,21 +81,22 @@ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= -github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= -github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/pflag v1.0.7 h1:vN6T9TfwStFPFM5XzjsvmzZkLuaLX+HS+0SeFLRgU6M= -github.com/spf13/pflag v1.0.7/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s= +github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0= +github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= +github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/tmuniversal/papercrypt v1.3.0 h1:k0Tbsc6PEj9AT8bbkkAAxZCy8HuIMCn0k4Yp64gJkGg= +github.com/tmuniversal/papercrypt v1.3.0/go.mod h1:DWhBiAoHCPVFSr+OMyXAB3qjeJeyLq91NeZWP3Bs65k= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4= -golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc= +golang.org/x/crypto v0.42.0 h1:chiH31gIWm57EkTXpwnqf8qeuMUi0yekh6mT2AvFlqI= +golang.org/x/crypto v0.42.0/go.mod h1:4+rDnOTJhQCx2q7/j6rAN5XDw8kPjeaXEUR2eL94ix8= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= @@ -109,20 +117,20 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI= -golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k= +golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.34.0 h1:O/2T7POpk0ZZ7MAzMeWFSg6S5IpWd/RXDlM9hgM3DR4= -golang.org/x/term v0.34.0/go.mod h1:5jC53AEywhIVebHgPVeg0mj8OD3VO9OzclacVrqpaAw= +golang.org/x/term v0.35.0 h1:bZBVKBudEyhRcajGcNc3jIfWPqV4y/Kt2XcoigOWtDQ= +golang.org/x/term v0.35.0/go.mod h1:TPGtkTLesOwf2DE8CgVYiZinHAOuy5AYUYT1lENIZnA= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng= -golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU= +golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= +golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= @@ -131,6 +139,7 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da h1:noIWHXmPHxILtqtCOPIhSt0ABwskkZKjD3bXGnZGpNY= golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/container_file.go b/internal/container_file.go index 27f8ac5..1810a9d 100644 --- a/internal/container_file.go +++ b/internal/container_file.go @@ -35,7 +35,7 @@ import ( "strings" "time" - "github.com/ProtonMail/gopenpgp/v2/crypto" + "github.com/ProtonMail/gopenpgp/v3/crypto" "github.com/boombuler/barcode" "github.com/boombuler/barcode/aztec" "github.com/boombuler/barcode/qr" @@ -629,12 +629,18 @@ func (p *PaperCrypt) Decode(passphrase []byte) ([]byte, error) { pgpMessage := crypto.NewPGPMessage(decompressed.Bytes()) // 9. Decrypt secretContents - decryptedMessage, err := crypto.DecryptMessageWithPassword(pgpMessage, passphrase) + pgp := crypto.PGP() + decHandle, err := pgp.Decryption().Password(passphrase).New() if err != nil { - return nil, errors.Join(errors.New("error decrypting secret contents"), err) + return nil, errors.Join(errors.New("error creating decryption handle"), err) } - data = decryptedMessage.GetBinary() + decrypted, err := decHandle.Decrypt(pgpMessage.Bytes(), crypto.Bytes) + if err != nil { + return nil, errors.Join(errors.New("error decrypting data"), err) + } + + data = decrypted.Bytes() } // 10. Decompress content @@ -804,7 +810,7 @@ func DeserializeV2Text( switch dataFormat { case PaperCryptDataFormatPGP: pgpMessage = crypto.NewPGPMessage(body) - body = pgpMessage.GetBinary() + body = pgpMessage.Bytes() case PaperCryptDataFormatRaw: // do nothing default: diff --git a/internal/container_file_v1.go b/internal/container_file_v1.go index 2e1feb3..7bdf838 100644 --- a/internal/container_file_v1.go +++ b/internal/container_file_v1.go @@ -24,7 +24,6 @@ import ( "bytes" "compress/gzip" "crypto/sha256" - "encoding/base64" "encoding/json" "errors" "fmt" @@ -32,7 +31,7 @@ import ( "strings" "time" - "github.com/ProtonMail/gopenpgp/v2/crypto" + "github.com/ProtonMail/gopenpgp/v3/crypto" "github.com/caarlos0/log" ) @@ -71,7 +70,7 @@ type PaperCryptV1 struct { // NewPaperCryptV1 creates a new paper crypt func NewPaperCryptV1(version string, data *crypto.PGPMessage, serialNumber string, purpose string, comment string, createdAt time.Time) *PaperCryptV1 { - binData := data.GetBinary() + binData := data.Bytes() dataCRC24 := Crc24Checksum(binData) dataCRC32 := crc32.ChecksumIEEE(binData) @@ -96,7 +95,7 @@ func NewPaperCryptV1(version string, data *crypto.PGPMessage, serialNumber strin func (p *PaperCryptV1) ToNextVersion() (*PaperCrypt, error) { data := new(bytes.Buffer) gzipWriter := gzip.NewWriter(data) - if _, err := gzipWriter.Write(p.Data.GetBinary()); err != nil { + if _, err := gzipWriter.Write(p.Data.Bytes()); err != nil { return nil, errors.Join(errors.New("error compressing data"), err) } if err := gzipWriter.Close(); err != nil { @@ -117,69 +116,6 @@ func (p *PaperCryptV1) ToNextVersion() (*PaperCrypt, error) { }, nil } -func (p *PaperCryptV1) GetBinary() []byte { - return p.Data.GetBinary() -} - -func (p *PaperCryptV1) GetBinarySerialized() string { - data := p.GetBinary() - return SerializeBinaryV1(&data) -} - -func (p *PaperCryptV1) GetLength() int { - return len(p.GetBinary()) -} - -func (p *PaperCryptV1) GetText(lowerCaseEncoding bool) ([]byte, error) { - header := fmt.Sprintf( - `%s: %s -%s: %s -%s: %s -%s: %s -%s: %s -%s: %d -%s: %06x -%s: %08x -%s: %s`, - HeaderFieldVersion, - p.Version, - HeaderFieldSerial, - p.SerialNumber, - HeaderFieldPurpose, - p.Purpose, - HeaderFieldComment, - p.Comment, - HeaderFieldDate, - p.CreatedAt.Format(TimeStampFormatLongTZ), - HeaderFieldContentLength, - p.GetLength(), - HeaderFieldCRC24, - p.DataCRC24, - HeaderFieldCRC32, - p.DataCRC32, - HeaderFieldSHA256, - base64.StdEncoding.EncodeToString(p.DataSHA256[:])) - - headerCRC32 := crc32.ChecksumIEEE([]byte(header)) - - serializedData := p.GetBinarySerialized() - if lowerCaseEncoding { - serializedData = strings.ToLower(serializedData) - } - - return []byte( - fmt.Sprintf(`%s -%s: %08x - - -%s -`, - header, - HeaderFieldHeaderCRC32, - headerCRC32, - serializedData)), nil -} - func DeserializeV1Text(data []byte, ignoreVersionMismatch bool, ignoreChecksumMismatch bool) (*PaperCrypt, error) { paperCryptFileContents := NormalizeLineEndings(data) @@ -257,7 +193,7 @@ func DeserializeV1Text(data []byte, ignoreVersionMismatch bool, ignoreChecksumMi pgpMessage = crypto.NewPGPMessage(body) // 5. Verify Body Hashes - body = pgpMessage.GetBinary() + body = pgpMessage.Bytes() // 5.1 Verify Content Length bodyLength, ok := headers[HeaderFieldContentLength] diff --git a/internal/crc_test.go b/internal/crc_test.go index 54b6bd9..a0fbf96 100644 --- a/internal/crc_test.go +++ b/internal/crc_test.go @@ -22,6 +22,8 @@ package internal import ( "testing" + + "github.com/stretchr/testify/assert" ) func TestChecksumValidation(t *testing.T) { @@ -29,10 +31,11 @@ func TestChecksumValidation(t *testing.T) { generateCRCTable() checksum := Crc24Checksum(data) - valid := ValidateCRC24(data, checksum) - if !valid { - t.Errorf("Expected checksum validation to be true, but got false.") - } + assert.True( + t, + ValidateCRC24(data, checksum), + "Expected determined checksum to be valid, but was not.", + ) } func TestChecksumInvalidation(t *testing.T) { @@ -43,10 +46,11 @@ func TestChecksumInvalidation(t *testing.T) { // Modify the data to invalidate the checksum data[0] = 0xAB - valid := ValidateCRC24(data, checksum) - if valid { - t.Errorf("Expected checksum validation to be false, but got true.") - } + assert.False( + t, + ValidateCRC24(data, checksum), + "Expected checksum validation to fail for changed data, but got true.", + ) } func TestBoth(t *testing.T) { @@ -77,6 +81,11 @@ func TestBoth(t *testing.T) { generateCRCTable() checksum := uint32(0xc55238) + assert.True( + t, + ValidateCRC24(data, checksum), + "Expected checksum validation to be true for pre-determined valid checksum, but got false.", + ) valid := ValidateCRC24(data, checksum) if !valid { t.Errorf("Expected checksum validation to be true, but got false.") @@ -110,8 +119,9 @@ func TestValidateCRC32(t *testing.T) { } checksum := uint32(0x59f08912) - valid := ValidateCRC32(data, checksum) - if !valid { - t.Errorf("Expected checksum validation to be true, but got false.") - } + assert.True( + t, + ValidateCRC32(data, checksum), + "Expected checksum validation to pass for pre-determined valid checksum, but got false.", + ) }