Skip to content

Commit

Permalink
optimize according to the comment
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyuhang0 committed Aug 17, 2023
1 parent 9e94e22 commit 48fc37a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,18 +157,19 @@ You usually need not specify the caCert, unless the certificate is not included
in the default root certificates.

```ts
import { Client } from "https://deno.land/x/mysql/mod.ts";
import { Client, TLSConfig, TLSMode } from "https://deno.land/x/mysql/mod.ts";
const tlsConfig: TLSConfig = {
mode: TLSMode.VERIFY_IDENTITY,
caCerts: [
await Deno.readTextFile("capath"),
]
}
const client = await new Client().connect({
hostname: "127.0.0.1",
username: "root",
db: "dbname",
password: "password",
tls: {
mode: "verify_identity",
caCerts: [
await Deno.readTextFile("capath"),
],
},
tls: tlsConfig,
});
```

Expand Down
2 changes: 2 additions & 0 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export type { ClientConfig } from "./src/client.ts";
export { Client } from "./src/client.ts";
export type { TLSConfig } from "./src/client.ts";
export { TLSMode } from "./src/client.ts";

export type { ExecuteResult } from "./src/connection.ts";
export { Connection } from "./src/connection.ts";
Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export enum TLSMode {
*/
export interface TLSConfig {
/** mode of tls. only support disabled and verify_identity now*/
mode?: string;
mode?: TLSMode;
/** A list of root certificates (must be PEM format) that will be used in addition to the
* default root certificates to verify the peer's certificate. */
caCerts?: string[];
Expand Down
6 changes: 3 additions & 3 deletions src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export class Connection {
// TODO: implement connect timeout
if (
this.config.tls?.mode &&
this.config.tls.mode.toLocaleLowerCase() !== TLSMode.DISABLED &&
this.config.tls.mode.toLocaleLowerCase() !== TLSMode.VERIFY_IDENTITY
this.config.tls.mode !== TLSMode.DISABLED &&
this.config.tls.mode !== TLSMode.VERIFY_IDENTITY
) {
throw new Error("unsupported tls mode");
}
Expand All @@ -93,7 +93,7 @@ export class Connection {
// Deno.startTls() only supports VERIFY_IDENTITY now.
let isSSL = false;
if (
this.config.tls?.mode?.toLocaleLowerCase() === TLSMode.VERIFY_IDENTITY
this.config.tls?.mode === TLSMode.VERIFY_IDENTITY
) {
if (
(handshakePacket.serverCapabilities &
Expand Down
5 changes: 1 addition & 4 deletions src/packets/builders/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ export function buildAuth(
packet: HandshakeBody,
params: { username: string; password?: string; db?: string; ssl?: boolean },
): Uint8Array {
const clientParam: number = clientCapabilities(packet, {
db: params.db,
ssl: params.ssl,
});
const clientParam: number = clientCapabilities(packet, params);

if (packet.serverCapabilities & ServerCapabilities.CLIENT_PLUGIN_AUTH) {
const writer = new BufferWriter(new Uint8Array(1000));
Expand Down

0 comments on commit 48fc37a

Please sign in to comment.