(opts setOpts)
| 22 | } |
| 23 | |
| 24 | func set(opts setOpts) ([]byte, bool, error) { |
| 25 | // Load the file |
| 26 | // TODO: Issue #173: if the file does not exist, create it with the contents passed in as opts.Value |
| 27 | tree, err := common.LoadEncryptedFileWithBugFixes(common.GenericDecryptOpts{ |
| 28 | Cipher: opts.Cipher, |
| 29 | InputStore: opts.InputStore, |
| 30 | InputPath: opts.InputPath, |
| 31 | IgnoreMAC: opts.IgnoreMAC, |
| 32 | KeyServices: opts.KeyServices, |
| 33 | }) |
| 34 | if err != nil { |
| 35 | return nil, false, err |
| 36 | } |
| 37 | |
| 38 | // Decrypt the file |
| 39 | dataKey, err := common.DecryptTree(common.DecryptTreeOpts{ |
| 40 | Cipher: opts.Cipher, |
| 41 | IgnoreMac: opts.IgnoreMAC, |
| 42 | Tree: tree, |
| 43 | KeyServices: opts.KeyServices, |
| 44 | DecryptionOrder: opts.DecryptionOrder, |
| 45 | }) |
| 46 | if err != nil { |
| 47 | return nil, false, err |
| 48 | } |
| 49 | |
| 50 | // Set the value |
| 51 | var changed bool |
| 52 | tree.Branches[0], changed = tree.Branches[0].Set(opts.TreePath, opts.Value) |
| 53 | |
| 54 | if err, code := validateFileForEncryption(opts.OutputStore, tree.Branches); err != nil { |
| 55 | return nil, false, common.NewExitError(err, code) |
| 56 | } |
| 57 | |
| 58 | err = common.EncryptTree(common.EncryptTreeOpts{ |
| 59 | DataKey: dataKey, Tree: tree, Cipher: opts.Cipher, |
| 60 | }) |
| 61 | if err != nil { |
| 62 | return nil, false, err |
| 63 | } |
| 64 | |
| 65 | encryptedFile, err := opts.OutputStore.EmitEncryptedFile(*tree) |
| 66 | if err != nil { |
| 67 | return nil, false, common.NewExitError(fmt.Sprintf("Could not marshal tree: %s", err), codes.ErrorDumpingTree) |
| 68 | } |
| 69 | return encryptedFile, changed, err |
| 70 | } |
no test coverage detected