Home | History | Annotate | Download | only in syncable
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Various utility methods for nigory-based multi-type encryption.
      6 
      7 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_NIGORI_UTIL_H_
      8 #define CHROME_BROWSER_SYNC_SYNCABLE_NIGORI_UTIL_H_
      9 #pragma once
     10 
     11 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h"
     12 #include "chrome/browser/sync/syncable/model_type.h"
     13 
     14 namespace browser_sync {
     15 class Cryptographer;
     16 }
     17 
     18 namespace syncable {
     19 
     20 class BaseTransaction;
     21 class ReadTransaction;
     22 class WriteTransaction;
     23 
     24 // Returns the set of datatypes that require encryption as specified by the
     25 // Sync DB's nigori node. This will never include passwords, as the encryption
     26 // status of that is always on if passwords are enabled..
     27 ModelTypeSet GetEncryptedDataTypes(BaseTransaction* const trans);
     28 
     29 // Extract the set of encrypted datatypes from a nigori node.
     30 ModelTypeSet GetEncryptedDataTypesFromNigori(
     31     const sync_pb::NigoriSpecifics& nigori);
     32 
     33 // Set the encrypted datatypes on the nigori node.
     34 void FillNigoriEncryptedTypes(const ModelTypeSet& types,
     35     sync_pb::NigoriSpecifics* nigori);
     36 
     37 // Check if our unsyced changes are encrypted if they need to be based on
     38 // |encrypted_types|.
     39 // Returns: true if all unsynced data that should be encrypted is.
     40 //          false if some unsynced changes need to be encrypted.
     41 // This method is similar to ProcessUnsyncedChangesForEncryption but does not
     42 // modify the data and does not care if data is unnecessarily encrypted.
     43 bool VerifyUnsyncedChangesAreEncrypted(
     44     BaseTransaction* const trans,
     45     const ModelTypeSet& encrypted_types);
     46 
     47 // Processes all unsynced changes and ensures they are appropriately encrypted
     48 // or unencrypted, based on |encrypted_types|.
     49 bool ProcessUnsyncedChangesForEncryption(
     50     WriteTransaction* const trans,
     51     const syncable::ModelTypeSet& encrypted_types,
     52     browser_sync::Cryptographer* cryptographer);
     53 
     54 // Verifies all data of type |type| is encrypted if |is_encrypted| is true or is
     55 // unencrypted otherwise.
     56 bool VerifyDataTypeEncryption(BaseTransaction* const trans,
     57                               ModelType type,
     58                               bool is_encrypted);
     59 
     60 }  // namespace syncable
     61 
     62 #endif  // CHROME_BROWSER_SYNC_SYNCABLE_NIGORI_UTIL_H_
     63