Use a stable device-user identifier for CryptAuth enrollments.
This id should not change if the same user is removed and added to the same
device.
BUG=455515
TEST=removed account, added account back and id is still the same
Review URL: https://codereview.chromium.org/877033005
Cr-Commit-Position: refs/heads/master@{#318001}
diff --git a/components/proximity_auth/cryptauth/cryptauth_enrollment_utils.cc b/components/proximity_auth/cryptauth/cryptauth_enrollment_utils.cc
new file mode 100644
index 0000000..f9aafcb
--- /dev/null
+++ b/components/proximity_auth/cryptauth/cryptauth_enrollment_utils.cc
@@ -0,0 +1,20 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/proximity_auth/cryptauth/cryptauth_enrollment_utils.h"
+
+#include "base/sha1.h"
+#include "components/proximity_auth/base64url.h"
+
+namespace proximity_auth {
+
+std::string CalculateDeviceUserId(const std::string& device_id,
+ const std::string& user_id) {
+ std::string device_user_id;
+ Base64UrlEncode(base::SHA1HashString(device_id + "|" + user_id),
+ &device_user_id);
+ return device_user_id;
+}
+
+} // namespace proximity_auth