| 1 | package docs |
| 2 | |
| 3 | import "fmt" |
| 4 | |
| 5 | func (c *contentCipher) sealUpdate(guid string, row *DocUpdate) error { |
| 6 | sealed, err := c.seal(contentUpdateKind, guid, row.Seq, 0, row.UpdateBin) |
| 7 | if err != nil { |
| 8 | return fmt.Errorf("docs: seal update %d: %w", row.ID, err) |
| 9 | } |
| 10 | row.UpdateBin = sealed |
| 11 | row.ContentEncoding = contentEncoding |
| 12 | return nil |
| 13 | } |
| 14 | |
| 15 | func (c *contentCipher) openUpdate(guid string, row *DocUpdate) error { |
| 16 | if row.ContentEncoding != contentEncoding { |
| 17 | return errContentEncoding |
| 18 | } |
| 19 | plain, err := c.open(contentUpdateKind, guid, row.Seq, 0, row.UpdateBin) |
| 20 | if err != nil { |
| 21 | return fmt.Errorf("docs: open update %d: %w", row.ID, err) |
| 22 | } |
| 23 | row.UpdateBin = plain |
| 24 | return nil |
| 25 | } |
| 26 | |
| 27 | func (c *contentCipher) sealSnapshot(guid string, row *DocSnapshot) error { |
| 28 | sealed, err := c.seal(contentSnapshotKind, guid, row.Seq, row.ABIVersion, row.State) |
| 29 | if err != nil { |
| 30 | return fmt.Errorf("docs: seal snapshot %d: %w", row.ID, err) |
| 31 | } |
| 32 | row.State = sealed |
| 33 | row.ContentEncoding = contentEncoding |
| 34 | return nil |
| 35 | } |
| 36 | |
| 37 | func (c *contentCipher) openSnapshot(guid string, row *DocSnapshot) error { |
| 38 | if row.ContentEncoding != contentEncoding { |
| 39 | return errContentEncoding |
| 40 | } |
| 41 | plain, err := c.open(contentSnapshotKind, guid, row.Seq, row.ABIVersion, row.State) |
| 42 | if err != nil { |
| 43 | return fmt.Errorf("docs: open snapshot %d: %w", row.ID, err) |
| 44 | } |
| 45 | row.State = plain |
| 46 | return nil |
| 47 | } |
| 48 | |
| 49 | // A report has no seq or ABI of its own; it is the document's one |
| 50 | // report, so both are 0 in its associated data and the kind byte keeps it |
| 51 | // apart. |
| 52 | func (c *contentCipher) sealReport(guid string, row *DocImportReport) error { |
| 53 | sealed, err := c.seal(contentReportKind, guid, 0, 0, row.ReportBin) |
| 54 | if err != nil { |
| 55 | return fmt.Errorf("docs: seal import report: %w", err) |
| 56 | } |
| 57 | row.ReportBin = sealed |
| 58 | row.ContentEncoding = contentEncoding |
| 59 | return nil |
| 60 | } |
| 61 | |
| 62 | func (c *contentCipher) openReport(guid string, row *DocImportReport) error { |
| 63 | if row.ContentEncoding != contentEncoding { |
| 64 | return errContentEncoding |
| 65 | } |
| 66 | plain, err := c.open(contentReportKind, guid, 0, 0, row.ReportBin) |
| 67 | if err != nil { |
| 68 | return fmt.Errorf("docs: open import report %d: %w", row.ID, err) |
| 69 | } |
| 70 | row.ReportBin = plain |
| 71 | return nil |
| 72 | } |
| 73 | |