MCPcopy
hub / github.com/FiloSottile/age / TestEncryptDecryptScrypt

Function TestEncryptDecryptScrypt

age_test.go:159–194  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

157}
158
159func TestEncryptDecryptScrypt(t *testing.T) {
160 password := "twitch.tv/filosottile"
161
162 r, err := age.NewScryptRecipient(password)
163 if err != nil {
164 t.Fatal(err)
165 }
166 r.SetWorkFactor(15)
167 buf := &bytes.Buffer{}
168 w, err := age.Encrypt(buf, r)
169 if err != nil {
170 t.Fatal(err)
171 }
172 if _, err := io.WriteString(w, helloWorld); err != nil {
173 t.Fatal(err)
174 }
175 if err := w.Close(); err != nil {
176 t.Fatal(err)
177 }
178
179 i, err := age.NewScryptIdentity(password)
180 if err != nil {
181 t.Fatal(err)
182 }
183 out, err := age.Decrypt(buf, i)
184 if err != nil {
185 t.Fatal(err)
186 }
187 outBytes, err := io.ReadAll(out)
188 if err != nil {
189 t.Fatal(err)
190 }
191 if string(outBytes) != helloWorld {
192 t.Errorf("wrong data: %q, excepted %q", outBytes, helloWorld)
193 }
194}
195
196func ExampleDecryptReaderAt() {
197 identity, err := age.ParseX25519Identity(privateKey)

Callers

nothing calls this directly

Calls 6

SetWorkFactorMethod · 0.95
NewScryptRecipientFunction · 0.92
EncryptFunction · 0.92
NewScryptIdentityFunction · 0.92
DecryptFunction · 0.92
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…