bitwarden-android/src/App/Services/AppIdService.cs

40 lines
1.1 KiB
C#
Raw Normal View History

2016-06-22 05:29:29 +03:00
using System;
using Bit.App.Abstractions;
namespace Bit.App.Services
{
public class AppIdService : IAppIdService
{
private const string AppIdKey = "appId";
private readonly ISecureStorageService _secureStorageService;
private Guid? _appId;
2016-06-22 05:29:29 +03:00
public AppIdService(ISecureStorageService secureStorageService)
2016-06-22 05:29:29 +03:00
{
_secureStorageService = secureStorageService;
2016-06-22 05:29:29 +03:00
}
public string AppId
{
get
{
if(_appId.HasValue)
2016-06-22 05:29:29 +03:00
{
return _appId.Value.ToString();
2016-06-22 05:29:29 +03:00
}
var appIdBytes = _secureStorageService.Retrieve(AppIdKey);
if(appIdBytes != null)
2016-06-22 05:29:29 +03:00
{
_appId = new Guid(appIdBytes);
return _appId.Value.ToString();
2016-06-22 05:29:29 +03:00
}
_appId = Guid.NewGuid();
_secureStorageService.Store(AppIdKey, _appId.Value.ToByteArray());
return _appId.Value.ToString();
2016-06-22 05:29:29 +03:00
}
}
}
}