(ctx context.Context)
| 44 | } |
| 45 | |
| 46 | func (d *Crypt) Init(ctx context.Context) error { |
| 47 | // obfuscate credentials if it's updated or just created |
| 48 | err := d.updateObfusParm(&d.Password) |
| 49 | if err != nil { |
| 50 | return fmt.Errorf("failed to obfuscate password: %w", err) |
| 51 | } |
| 52 | err = d.updateObfusParm(&d.Salt) |
| 53 | if err != nil { |
| 54 | return fmt.Errorf("failed to obfuscate salt: %w", err) |
| 55 | } |
| 56 | |
| 57 | isCryptExt := regexp.MustCompile(`^[.][A-Za-z0-9-_]{2,}$`).MatchString |
| 58 | if !isCryptExt(d.EncryptedSuffix) { |
| 59 | return fmt.Errorf("EncryptedSuffix is Illegal") |
| 60 | } |
| 61 | d.FileNameEncoding = utils.GetNoneEmpty(d.FileNameEncoding, "base64") |
| 62 | d.EncryptedSuffix = utils.GetNoneEmpty(d.EncryptedSuffix, ".bin") |
| 63 | d.RemotePath = utils.FixAndCleanPath(d.RemotePath) |
| 64 | |
| 65 | p, _ := strings.CutPrefix(d.Password, obfuscatedPrefix) |
| 66 | p2, _ := strings.CutPrefix(d.Salt, obfuscatedPrefix) |
| 67 | config := configmap.Simple{ |
| 68 | "password": p, |
| 69 | "password2": p2, |
| 70 | "filename_encryption": d.FileNameEnc, |
| 71 | "directory_name_encryption": d.DirNameEnc, |
| 72 | "filename_encoding": d.FileNameEncoding, |
| 73 | "suffix": d.EncryptedSuffix, |
| 74 | "pass_bad_blocks": "", |
| 75 | } |
| 76 | c, err := rcCrypt.NewCipher(config) |
| 77 | if err != nil { |
| 78 | return fmt.Errorf("failed to create Cipher: %w", err) |
| 79 | } |
| 80 | d.cipher = c |
| 81 | |
| 82 | return nil |
| 83 | } |
| 84 | |
| 85 | func (d *Crypt) updateObfusParm(str *string) error { |
| 86 | temp := *str |
nothing calls this directly
no test coverage detected