Skip to content

Commit

Permalink
Wrap structs with properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Dadoum authored Nov 21, 2023
1 parent 60361b9 commit 2e4146d
Showing 1 changed file with 52 additions and 22 deletions.
74 changes: 52 additions & 22 deletions lib/provision/adi.d
Original file line number Diff line number Diff line change
Expand Up @@ -128,28 +128,38 @@ public class ADI {
}

struct SynchronizationResumeMetadata {
public ubyte[] synchronizationResumeMetadata;
public ubyte[] machineIdentifier;
public ubyte[] _synchronizationResumeMetadata;
public ubyte[] _machineIdentifier;
private ADI adi;

this(this) {
synchronizationResumeMetadata = synchronizationResumeMetadata.dup;
machineIdentifier = machineIdentifier.dup;
_synchronizationResumeMetadata = _synchronizationResumeMetadata.dup;
_machineIdentifier = _machineIdentifier.dup;
adi = null;
}

this(ADI adiInstance, ubyte* srm, uint srmLength, ubyte* mid, uint midLength) {
adi = adiInstance;
synchronizationResumeMetadata = srm[0..srmLength];
machineIdentifier = mid[0..midLength];
_synchronizationResumeMetadata = srm[0..srmLength];
_machineIdentifier = mid[0..midLength];
}

~this() {
if (adi) {
adi.dispose(synchronizationResumeMetadata.ptr);
adi.dispose(machineIdentifier.ptr);
adi.dispose(_synchronizationResumeMetadata.ptr);
adi.dispose(_machineIdentifier.ptr);
}
}

pragma(inline, true)
auto synchronizationResumeMetadata() {
return _synchronizationResumeMetadata;
}

pragma(inline, true)
auto machineIdentifier() {
return _machineIdentifier;
}
}

public SynchronizationResumeMetadata synchronize(ulong dsId, ubyte[] serverIntermediateMetadata) {
Expand Down Expand Up @@ -186,26 +196,36 @@ public class ADI {
}

struct ClientProvisioningIntermediateMetadata {
public ubyte[] clientProvisioningIntermediateMetadata;
public uint session;
public ubyte[] _clientProvisioningIntermediateMetadata;
public uint _session;
private ADI adi;

this(this) {
clientProvisioningIntermediateMetadata = clientProvisioningIntermediateMetadata.dup;
_clientProvisioningIntermediateMetadata = _clientProvisioningIntermediateMetadata.dup;
adi = null;
}

this(ADI adiInstance, ubyte* cpim, uint cpimLength, uint session) {
adi = adiInstance;
clientProvisioningIntermediateMetadata = cpim[0..cpimLength];
this.session = session;
_clientProvisioningIntermediateMetadata = cpim[0..cpimLength];
this._session = session;
}

~this() {
if (adi) {
adi.dispose(clientProvisioningIntermediateMetadata.ptr);
adi.dispose(_clientProvisioningIntermediateMetadata.ptr);
}
}

pragma(inline, true)
auto clientProvisioningIntermediateMetadata() {
return _clientProvisioningIntermediateMetadata;
}

pragma(inline, true)
auto session() {
return _session;
}
}

public ClientProvisioningIntermediateMetadata startProvisioning(ulong dsId, ubyte[] serverProvisioningIntermediateMetadata) {
Expand Down Expand Up @@ -242,28 +262,38 @@ public class ADI {
}

struct OneTimePassword {
public ubyte[] oneTimePassword;
public ubyte[] machineIdentifier;
public ubyte[] _oneTimePassword;
public ubyte[] _machineIdentifier;
private ADI adi;

this(this) {
oneTimePassword = oneTimePassword.dup;
machineIdentifier = machineIdentifier.dup;
_oneTimePassword = _oneTimePassword.dup;
_machineIdentifier = _machineIdentifier.dup;
adi = null;
}

this(ADI adiInstance, ubyte* otp, uint otpLength, ubyte* mid, uint midLength) {
adi = adiInstance;
oneTimePassword = otp[0..otpLength];
machineIdentifier = mid[0..midLength];
_oneTimePassword = otp[0..otpLength];
_machineIdentifier = mid[0..midLength];
}

~this() {
if (adi) {
adi.dispose(oneTimePassword.ptr);
adi.dispose(machineIdentifier.ptr);
adi.dispose(_oneTimePassword.ptr);
adi.dispose(_machineIdentifier.ptr);
}
}

pragma(inline, true)
auto oneTimePassword() {
return _oneTimePassword;
}

pragma(inline, true)
auto machineIdentifier() {
return _machineIdentifier;
}
}

public OneTimePassword requestOTP(ulong dsId) {
Expand Down

0 comments on commit 2e4146d

Please sign in to comment.