hash_util.cc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2016 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. #include "components/sync/base/hash_util.h"
  5. #include "base/base64.h"
  6. #include "base/hash/sha1.h"
  7. #include "base/notreached.h"
  8. #include "base/strings/string_number_conversions.h"
  9. #include "components/sync/base/model_type.h"
  10. #include "components/sync/protocol/autofill_offer_specifics.pb.h"
  11. #include "components/sync/protocol/autofill_specifics.pb.h"
  12. #include "components/sync/protocol/entity_specifics.pb.h"
  13. namespace syncer {
  14. std::string GenerateSyncableBookmarkHash(
  15. const std::string& originator_cache_guid,
  16. const std::string& originator_client_item_id) {
  17. // Blank PB with just the field in it has termination symbol,
  18. // handy for delimiter.
  19. sync_pb::EntitySpecifics serialized_type;
  20. AddDefaultFieldValue(BOOKMARKS, &serialized_type);
  21. std::string hash_input;
  22. serialized_type.AppendToString(&hash_input);
  23. hash_input.append(originator_cache_guid + originator_client_item_id);
  24. std::string encode_output;
  25. base::Base64Encode(base::SHA1HashString(hash_input), &encode_output);
  26. return encode_output;
  27. }
  28. std::string GetUnhashedClientTagFromAutofillWalletSpecifics(
  29. const sync_pb::AutofillWalletSpecifics& specifics) {
  30. switch (specifics.type()) {
  31. case sync_pb::AutofillWalletSpecifics::MASKED_CREDIT_CARD:
  32. return specifics.masked_card().id();
  33. case sync_pb::AutofillWalletSpecifics::POSTAL_ADDRESS:
  34. return specifics.address().id();
  35. case sync_pb::AutofillWalletSpecifics::CUSTOMER_DATA:
  36. return specifics.customer_data().id();
  37. case sync_pb::AutofillWalletSpecifics::CREDIT_CARD_CLOUD_TOKEN_DATA:
  38. return specifics.cloud_token_data().instrument_token();
  39. case sync_pb::AutofillWalletSpecifics::UNKNOWN:
  40. NOTREACHED();
  41. return std::string();
  42. }
  43. return std::string();
  44. }
  45. std::string GetUnhashedClientTagFromAutofillOfferSpecifics(
  46. const sync_pb::AutofillOfferSpecifics& specifics) {
  47. return base::NumberToString(specifics.id());
  48. }
  49. } // namespace syncer