newCipherForConfig constructs a Cipher for the given config name
(opt *Options)
| 178 | |
| 179 | // newCipherForConfig constructs a Cipher for the given config name |
| 180 | func newCipherForConfig(opt *Options) (*Cipher, error) { |
| 181 | mode, err := NewNameEncryptionMode(opt.FilenameEncryption) |
| 182 | if err != nil { |
| 183 | return nil, err |
| 184 | } |
| 185 | if opt.Password == "" { |
| 186 | return nil, errors.New("password not set in config file") |
| 187 | } |
| 188 | password, err := obscure.Reveal(opt.Password) |
| 189 | if err != nil { |
| 190 | return nil, fmt.Errorf("failed to decrypt password: %w", err) |
| 191 | } |
| 192 | var salt string |
| 193 | if opt.Password2 != "" { |
| 194 | salt, err = obscure.Reveal(opt.Password2) |
| 195 | if err != nil { |
| 196 | return nil, fmt.Errorf("failed to decrypt password2: %w", err) |
| 197 | } |
| 198 | } |
| 199 | enc, err := NewNameEncoding(opt.FilenameEncoding) |
| 200 | if err != nil { |
| 201 | return nil, err |
| 202 | } |
| 203 | cipher, err := newCipher(mode, password, salt, opt.DirectoryNameEncryption, enc) |
| 204 | if err != nil { |
| 205 | return nil, fmt.Errorf("failed to make cipher: %w", err) |
| 206 | } |
| 207 | cipher.setEncryptedSuffix(opt.Suffix) |
| 208 | cipher.setPassBadBlocks(opt.PassBadBlocks) |
| 209 | return cipher, nil |
| 210 | } |
| 211 | |
| 212 | // NewCipher constructs a Cipher for the given config |
| 213 | func NewCipher(m configmap.Mapper) (*Cipher, error) { |
no test coverage detected
searching dependent graphs…