setSPP method
Sets a Semi Permanent Passcode(SPP) in the secondary server key-store. A Semi Permanent Passcode (SPP) is 6 character alpha-numeric for submitting an enrollment request. Only the connections which have access to manage namespace are allowed to set SPP
Returns "ok" when SPP is set successfully.
Throws InvalidPinException when an invalid SPP is provided.
Throws AtClientException when an enrollmentId does not exist.
Throws AtClientException when an enrollmentId does not have access to "__manage" namespace.
AtResponse sppResponse = await atClient.setSPP(ABC123);
Implementation
@override
Future<AtResponse> setSPP(String spp) async {
// SPP should be 6 characters PIN. Throw exception if its less
// or more than 6 characters
if (spp.length != 6) {
throw InvalidPinException.message("$spp should be 6 characters");
}
// Validate the SPP. The SPP should contain only alpha-numeric characters.
// Any special characters or any characters other than aplha-numeric characters
// are not allowed. Throw an exception
bool hasMatch = RegExp(r'[\W-]+').hasMatch(spp);
if (hasMatch) {
throw InvalidPinException.message("$spp is not a valid SPP");
}
String? otpVerbResponse;
try {
otpVerbResponse =
await _remoteSecondary?.executeCommand('otp:put:$spp\n', auth: true);
} on AtLookUpException catch (e) {
throw AtClientException(e.errorCode, e.errorMessage);
} on AtException catch (e) {
throw AtClientException.message(e.message);
}
otpVerbResponse = otpVerbResponse?.replaceAll('data:', '');
return AtResponse()..response = otpVerbResponse!;
}