addKeyUsage method

void addKeyUsage({
  1. bool digitalSignature = false,
  2. bool nonRepudiation = false,
  3. bool keyEncipherment = false,
  4. bool dataEncipherment = false,
  5. bool keyAgreement = false,
  6. bool keyCertSign = false,
  7. bool cRLSign = false,
  8. bool encipherOnly = false,
  9. bool decipherOnly = false,
  10. bool critical = false,
})

Adds Key Usage extension (2.5.29.15).

Implementation

void addKeyUsage({
  bool digitalSignature = false,
  bool nonRepudiation = false,
  bool keyEncipherment = false,
  bool dataEncipherment = false,
  bool keyAgreement = false,
  bool keyCertSign = false,
  bool cRLSign = false,
  bool encipherOnly = false,
  bool decipherOnly = false,
  bool critical = false,
}) {
  _ensureUsable();

  final usages = <String>[];
  if (digitalSignature) usages.add('digitalSignature');
  if (nonRepudiation) usages.add('nonRepudiation');
  if (keyEncipherment) usages.add('keyEncipherment');
  if (dataEncipherment) usages.add('dataEncipherment');
  if (keyAgreement) usages.add('keyAgreement');
  if (keyCertSign) usages.add('keyCertSign');
  if (cRLSign) usages.add('cRLSign');
  if (encipherOnly) usages.add('encipherOnly');
  if (decipherOnly) usages.add('decipherOnly');

  if (usages.isEmpty) return;
  final parts = [if (critical) 'critical', ...usages].join(',');
  _addExtensionByName('keyUsage', parts);
}