using ServiceShared.Models.Response.Exception; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static ServiceShared.Models.Database.Device; using static ServiceShared.Models.Database.Results; namespace ServiceShared.Models.Request { public class Subscribe { /// /// SHA512 - Hash of Plz Geburtsdatum Sampleid /// public string pgs { get; set; } /// /// AES encrypted hash of Plz Geburtsdatum Sampleid, that can decrypted by inside service /// public string pgs_hash { get; set; } /// /// Unique id of mobile device /// public string udid { get; set; } /// /// DeviceToken for notification service /// public string device_token { get; set; } /// /// Type of mobile device /// public DeviceTypes device_type { get; set; } /// /// Public Key of mobile device /// public string client_public_key { get; set; } /// /// Client verification hash /// public string verificator_hash { get; set; } /// /// Client PIN that can reset password on the same device /// public string pin { get; set; } /// /// Validates a Subscribe object /// /// Returns exception if some of validation fails public static ResponseException Validate(Subscribe subscribe) { if (subscribe == null) { return new InvalidRequestException(); } else if (string.IsNullOrEmpty(subscribe.pgs)) { return new MissingArgumentException("pgs"); } else if (string.IsNullOrEmpty(subscribe.udid)) { return new MissingArgumentException("udid"); } else if (string.IsNullOrEmpty(subscribe.device_token)) { return new MissingArgumentException("device_token"); } else if (string.IsNullOrEmpty(subscribe.client_public_key)) { return new MissingArgumentException("client_public_key"); } else if (subscribe.device_type == DeviceTypes.NONE) { return new MissingArgumentException("device_type"); } else if (subscribe.pgs.Length != 128) { return new InvalidArgumentException("pgs", "wrong length"); } else if (subscribe.udid.Length < 10 || subscribe.udid.Length > 64) { return new InvalidArgumentException("udid", "wrong length"); } else if (subscribe.device_token.Length < 10 || subscribe.device_token.Length > 255) { return new InvalidArgumentException("device_token", "wrong length"); } else if (subscribe.client_public_key.Length < 32) { return new InvalidArgumentException("client_public_key", "wrong length"); } else if (string.IsNullOrEmpty(subscribe.verificator_hash)) { return new MissingArgumentException("verificator_hash"); } else if (subscribe.verificator_hash.Length != 128) { return new InvalidArgumentException("verificator_hash", "wrong length"); } else { return null; } } /// /// Converts CheckFileChecksum object to the subscribe object and validates it at least /// /// CheckFileChecksum object that should be validated /// Returns exception if some of validation fails public static ResponseException Validate(CheckFileChecksum checkFileChecksum) { return Validate(new Subscribe() { device_token = checkFileChecksum.device_token, device_type = checkFileChecksum.device_type, pgs = checkFileChecksum.pgs, client_public_key = checkFileChecksum.client_public_key, udid = checkFileChecksum.udid, verificator_hash = checkFileChecksum.verificator_hash }); } /// /// Converts current subscribe object to the Database.Results /// /// returns Database.Results public Database.Results ToResults() { return new Database.Results() { PGS = this.pgs, PGS_HASH = this.pgs_hash, UDID = this.udid, DeviceToken = this.device_token, DeviceType = this.device_type, ClientPublicKey = this.client_public_key, VerificationHash = this.verificator_hash, PIN = this.pin }; } } }