()
| 279 | } |
| 280 | |
| 281 | func (f *rotateFlags) valid() error { |
| 282 | if f.PostgresURL == "" { |
| 283 | return xerrors.Errorf("no database configured") |
| 284 | } |
| 285 | |
| 286 | if f.New == "" { |
| 287 | return xerrors.Errorf("no new key provided") |
| 288 | } |
| 289 | |
| 290 | if val, err := base64.StdEncoding.DecodeString(f.New); err != nil { |
| 291 | return xerrors.Errorf("new key must be base64-encoded") |
| 292 | } else if len(val) != 32 { |
| 293 | return xerrors.Errorf("new key must be exactly 32 bytes in length") |
| 294 | } |
| 295 | |
| 296 | for i, k := range f.Old { |
| 297 | if val, err := base64.StdEncoding.DecodeString(k); err != nil { |
| 298 | return xerrors.Errorf("old key at index %d must be base64-encoded", i) |
| 299 | } else if len(val) != 32 { |
| 300 | return xerrors.Errorf("old key at index %d must be exactly 32 bytes in length", i) |
| 301 | } |
| 302 | |
| 303 | // Pedantic, but typos here will ruin your day. |
| 304 | if k == f.New { |
| 305 | return xerrors.Errorf("old key at index %d is the same as the new key", i) |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | return nil |
| 310 | } |
| 311 | |
| 312 | type decryptFlags struct { |
| 313 | PostgresURL string |
no test coverage detected