2024-02-12 08:01:19 +08:00
|
|
|
//import { AbstractModel } from 'Knoin/AbstractModel';
|
|
|
|
|
|
|
|
export class MimeHeaderAutocryptModel/* extends AbstractModel*/
|
|
|
|
{
|
|
|
|
constructor(value) {
|
|
|
|
// super();
|
|
|
|
this.addr = '';
|
|
|
|
this.prefer_encrypt = 'nopreference', // nopreference or mutual
|
|
|
|
this.keydata = '';
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
value.split(';').forEach(entry => {
|
2024-06-04 19:08:33 +08:00
|
|
|
entry = entry.match(/^([^=]+)=(.*)$/);
|
2024-02-12 08:01:19 +08:00
|
|
|
const trim = str => (str || '').trim().replace(/^["']|["']+$/g, '');
|
2024-06-04 19:08:33 +08:00
|
|
|
this[trim(entry[1]).replace('-', '_')] = trim(entry[2]);
|
2024-02-12 08:01:19 +08:00
|
|
|
});
|
2024-06-04 19:08:33 +08:00
|
|
|
this.keydata = this.keydata.replace(/\s+/g, '\n');
|
2024-02-12 08:01:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toString() {
|
2024-06-04 19:08:33 +08:00
|
|
|
let result = `addr=${this.addr}; `;
|
2024-02-12 08:01:19 +08:00
|
|
|
if ('mutual' === this.prefer_encrypt) {
|
2024-06-04 19:08:33 +08:00
|
|
|
result += 'prefer-encrypt=mutual; ';
|
2024-02-12 08:01:19 +08:00
|
|
|
}
|
2024-06-04 19:08:33 +08:00
|
|
|
return result + 'keydata=' + this.keydata.replace(/\n/g, '\n ');
|
2024-02-12 08:01:19 +08:00
|
|
|
}
|
|
|
|
|
2024-02-21 01:14:32 +08:00
|
|
|
pem() {
|
2024-02-12 08:01:19 +08:00
|
|
|
return '-----BEGIN PGP PUBLIC KEY BLOCK-----\n\n'
|
|
|
|
+ this.keydata
|
|
|
|
+ '\n-----END PGP PUBLIC KEY BLOCK-----';
|
|
|
|
}
|
|
|
|
}
|