1
0
mirror of https://github.com/bitwarden/directory-connector synced 2025-12-24 04:04:29 +00:00

buf to guid

This commit is contained in:
Kyle Spearrin
2018-05-01 15:05:12 -04:00
parent bbcc65f149
commit d6707488c8

View File

@@ -11,6 +11,7 @@ import { ConfigurationService } from './configuration.service';
import { DirectoryService } from './directory.service'; import { DirectoryService } from './directory.service';
import { LogService } from 'jslib/abstractions/log.service'; import { LogService } from 'jslib/abstractions/log.service';
import { Utils } from 'jslib/misc/utils';
const UserControlAccountDisabled = 2; const UserControlAccountDisabled = 2;
@@ -198,7 +199,7 @@ export class LdapDirectoryService implements DirectoryService {
private getExternalId(item: any, referenceId: string) { private getExternalId(item: any, referenceId: string) {
const attrObj = this.getAttrObj(item, 'objectGUID'); const attrObj = this.getAttrObj(item, 'objectGUID');
if (attrObj != null && attrObj._vals != null && attrObj._vals.length > 0) { if (attrObj != null && attrObj._vals != null && attrObj._vals.length > 0) {
return makeGuidString(attrObj._vals[0]); return this.bufToGuid(attrObj._vals[0]);
} else { } else {
return referenceId; return referenceId;
} }
@@ -349,24 +350,14 @@ export class LdapDirectoryService implements DirectoryService {
}); });
}); });
} }
}
// ref: https://github.com/zefferus/uuid-parse/blob/parse/uuid-parse.js private bufToGuid(buf: Buffer) {
const p1 = buf.slice(0, 4).reverse().buffer;
const byteToHex: string[] = []; const p2 = buf.slice(4, 6).reverse().buffer;
for (let i = 0; i < 256; i++) { const p3 = buf.slice(6, 8).reverse().buffer;
byteToHex[i] = (i + 0x100).toString(16).substr(1); const p4 = buf.slice(8).buffer;
} const guid = Utils.fromBufferToHex(p1) + '-' + Utils.fromBufferToHex(p2) + '-' + Utils.fromBufferToHex(p3) +
'-' + Utils.fromBufferToHex(p4);
function makeGuidString(buf: Buffer) { return guid.toLowerCase();
let i = 0; }
const bth = byteToHex;
return bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] + '-' +
bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]] +
bth[buf[i++]] + bth[buf[i++]];
} }