MCPcopy
hub / github.com/dgraph-io/dgraph / GetWriter

Function GetWriter

enc/util.go:20–40  ·  view source on GitHub ↗

GetWriter wraps a crypto StreamWriter using the input key on the input Writer.

(key x.Sensitive, w io.Writer)

Source from the content-addressed store, hash-verified

18
19// GetWriter wraps a crypto StreamWriter using the input key on the input Writer.
20func GetWriter(key x.Sensitive, w io.Writer) (io.Writer, error) {
21 // No encryption, return the input writer as is.
22 if key == nil {
23 return w, nil
24 }
25 // Encryption, wrap crypto StreamWriter on the input Writer.
26 c, err := aes.NewCipher(key)
27 if err != nil {
28 return nil, err
29 }
30 iv, err := y.GenerateIV()
31 if err != nil {
32 return nil, err
33 }
34 if iv != nil {
35 if _, err = w.Write(iv); err != nil {
36 return nil, err
37 }
38 }
39 return cipher.StreamWriter{S: cipher.NewCTR(c, iv), W: w}, nil
40}
41
42// GetReader wraps a crypto StreamReader using the input key on the input Reader.
43func GetReader(key x.Sensitive, r io.Reader) (io.Reader, error) {

Callers 3

WriteBackupMethod · 0.92
openMethod · 0.92
writeGzDataFunction · 0.92

Calls 1

WriteMethod · 0.65

Tested by

no test coverage detected